Snap textframe size to content (like double-click in InDesign), including script support
A function appreciated by all in InDesign.. doubleclick the side of the boundingbox of a textframe and it snaps/scales immediately to the content.
I'm not talking about Type -> Area Type Options -> Auto-size
-
Several more fixes made to handle more complex cases and keep the baselines match exactly.
Meanwhile wanted to share this script also — I feel it touches a related problem: https://x.com/efficiency_d/status/2105433642994634919 -
Oh yeah, good catch. It doesn’t exist in Ai scripting, it’s how InDesign handles it... it should be `TextFrame.spacing` instead. But dead check around it 'worked' anyway, so it never crashed.
I found several more narrow cases it can do better with, and will revise it further. Meanwhile has updated the current script. Thanks. -
David Brown
commented
Your script is very interesting. I am confused by the statement on line 628, tf.textPath.insetSpacing. I do not see a text path's insetSpacing as a parameter is either JavaScript or AppleScript. I would appreciate an explanation.
-
Meanwhile I made a script for this: https://www.dropbox.com/scl/fi/vhvv51d8wuk86lx9n21od/FitAreaTypeFrame.jsx?rlkey=0q2he1xj0tlt177khzm68870n&dl=1
Supports English and Japanese locale.
Unfortunately, I was not able to find a way to toggle Auto-Size (height), only force enable it, but all other Fit options work — for rotated objects too (and it can convert irregular shapes into rectangles. Supports different text alignment (detecting it by the first line).
Hope this helps. Please feel free to test and use and comment. -
David Brown
commented
While I appreciate the comments pointing out the method of fitting text frames to text via double clicking on the handles, I was asking for the ability to do the fitting via AppleScript. I would like to avoid GUI scripting to accomplish the objective. Also, to those who suggest using Type>Area Type Options>Auto Size, that only resizes vertically.
-
David Brown
commented
I would find it very useful to be able to select a text field and instruct Illustrator to fit the text field to the text itself both vertically and horizontally. In addition to doing that manually, have an AppleScript command to do the same.
-
I actually clearly see the difference now, and agree these differ.
Auto-size in Ai makes the frame to auto-expand or auto-shrink vertically when text is added or removed, while keeping the width fixed. InDesign offers a lot more options in Text Frame Options > Auto-Size: height and width separately or together, proportionally or not, from a chosen corner or side, with minimum and maximum values...
But double-clicking a frame marker or a corner does a different thing altogether — it actually resizes the frame to hug the text from the side/sides needed at the moment, and it makes the text to overflow when it gets added later. It’s basically 'auto-size once'.
We can do the same thing though in a way already, utilizing something InDesign does not have — point text.
Double-clicking the round marker on the right side of the bounding box (or going Type > Convert to Point Type) and then clicking it again when it goes white effectively makes the frame hug the text tight, giving mostly the same results.
The downsides of this solution — it requires two precise double-clicks instead of one, and it drops all the Area Type Options if you had any (like Inset Spacing or First Baseline distance) — which is mentioned in this report: http://illustrator.uservoice.com/forums/333657/suggestions/47243432I’d say it’s close enough, but why not going a bit further and actually have it. Voted.
-
Robin, but why do you specifically say you don’t mean the 'Auto-size' option? What is the difference for you?
-
There's 'Auto Size' option in Type > Area Type Options that does this
-
James
commented
Be able to re-size text frame to fit content as per indesign. Constantly having to re-size text frames to fit the content.
-
Dan B
commented
Robin, you can already do that by double-clicking on the "prong" (for lack of a better word) that points downward from your Area Type, which will toggle the Auto-sizing of the area.
There's also a checkbox in Preferences > Type to make all new Area Type objects auto-size by default.