1 person found this helpful
1 person found this helpful
You can use text frame's fit method:
The width of the text (for left to right text) is the endHorizontalOffset of the last character minus the horizontalOffset of the first. You can size your frame based on that.
You can also use the horizontalOffsets of the insertionPoints, but that gets fun because sometimes the last insertionPoint is on the next line...
Thanks guys. the problem I'm having with fit to content is that it doesnt keep it on one line of text.
meaning the box gets resized to have the extension below the filename, as if there were a carraige return. It's strange behavior I thinks.
where I want it on one line
I'm going to give the offset business a go.
Just Apply No Break To Text Before Fitting Text Frame
Did you try my suggestion?
Honestly, I'm really new to this, so at every suggestion I have to figure out how to make it work. I've been spending the last 20 minutes trying to figure out how to apply a noBreak to this text fram
myTextFrame.textFramePreferences.noBreak = true;
myTextFrame.noBreak = true;
does not work for me.
I don't want to bother you guys with every little piece, so was trying to figure it out on my own. But since Im here, help please?
And I do want to try out the offset to understand it. But again, I'm new, I'll have to figure out the syntax.
Thank you Steven. That's got the syntax correct, but now I'm having a problem with the results.
This auto fit to content works great if the text frame is too big for the content to begin with. But if it's too small, it does not increase in size to fit the text. It's a shrink, not grow, result. At least, thats what I'm seeing.
so In order for this to work in my script, I would have to first create the text frame large enough to cover the size of expected filenames, which will work, but it's not neat. There is room for error.
Is this how the function is supposed to work, or am I doing something wrong?
Fit Frame To Content Only Increases Height Of Text Frame To Fit Text
But Not The Width. If It Works In For It
well its still a pretty cool function to know. Thanks for helping me with it.
I'll see if I can get something a bit neater with Harbs lead.
Thanks again everyone,
var myDoc = app.activeDocument;
var myTF = myDoc.textFrames;
var myViewPr = myDoc.viewPreferences;
var myHM = myViewPr.horizontalMeasurementUnits;
var myVM = myViewPr.verticalMeasurementUnits;
myViewPr.horizontalMeasurementUnits = MeasurementUnits.millimeters;
myViewPr.verticalMeasurementUnits = MeasurementUnits.millimeters;
var myBounds = myTF.geometricBounds;
myBounds += 1;
myTF.geometricBounds = myBounds;
myViewPr.horizontalMeasurementUnits = myHM;
myViewPr.verticalMeasurementUnits = myVM;
Here's what I was talking about...
var sel = app.selection; var line = sel.lines; var frame = line.parentTextFrames; var bounds = frame.visibleBounds; var lineWidth = line.characters[-1].endHorizontalOffset- line.characters.horizontalOffset; var centerPoint = bounds+((bounds-bounds)/2); bounds = centerPoint-(lineWidth/2); bounds = centerPoint+(lineWidth/2); frame.visibleBounds = bounds;
Thank you guys, I havent been in the office to try them out, but I will tonight. Thanks again for all the help.
Kasyan, that did exactly what I was looking for. thank you very much!