Skip to main content
Toques
Participating Frequently
August 14, 2021
Question

Fit Options - frame to content - Extendscript

  • August 14, 2021
  • 2 replies
  • 1790 views

I'm pretty familiar with using the FitOptions enums to, say, resize an image proportionally within its frame or snug a one-paragraph textFrame to its content by using FitOptions.FRAME_TO_CONTENT.

 

What I'm not sure how to do is: Given a textFrame with multiple paragraphs, how do I replicate the application behaviour of a user double clicking the bottom handle of that textFrame in ExtendScript? I guess any handle will do. It'd be all useful info.

 

Can it be done with inbuilt DOM methods or do I have to code it explicitly?

 

I understand FitOptions.FIT_FRAME_TO_CONTENT will snug a frame to the least possible X and Y values, given its content. But I only want to fit the frame to the content using its least possible Y values.

 

As an example, say, I've created a textFrame with geometricBounds of [2,2,7,4] in inches. If the parentStory.contents of that frame puts the bottom of the frame at four inches deep, how should I pull it up?

 

Thanks!

2 replies

Community Expert
August 16, 2021

Hi Toques,

is this text frame part of a story with several text frames threaded?

 

If not you could do it with auto height from the text frame options:

var tf = app.selection[0];

var props = 
{
	autoSizingReferencePoint : AutoSizingReferenceEnum.TOP_CENTER_POINT ,
	autoSizingType : AutoSizingTypeEnum.HEIGHT_ONLY ,
	useNoLineBreaksForAutoSizing : false ,
	verticalJustification : VerticalJustification.TOP_ALIGN	
};

tf.textFramePreferences.properties = props;

 

InDesign CS6 to InDesign 2021.

 

Regards,
Uwe Laubender

( ACP )

Toques
ToquesAuthor
Participating Frequently
August 14, 2021

There is a resize method for textFrames. Sorry folks, I should have read it fully before posting.

m1b
Community Expert
Community Expert
August 14, 2021

Hi, I'm interested how you did it. I've never done it before and this is what I came up with:

app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
var tf = app.activeDocument.selection[0];
var bounds = tf.geometricBounds;
var lastLine = tf.texts[0].lines.lastItem();
bounds[2] = lastLine.baseline;
tf.geometricBounds = bounds;

Is there a simpler way, eg. by using FIT_FRAME_TO_CONTENT?

- Mark

TᴀW
Legend
August 15, 2021

This is good, but not quite the same as double-clicking the bottom of the frame, because double-clicking will also increase the height of the frame if there is overset text in it, and your code won't.

So if that's a concern, you'd just have to first increase the height of the frame and then run your function.

But the essentials are all there in your code. I don't think there's a better way of doing it.

(I don't think the code will work for rotated frames, though... so that would be another complication to deal with if necessary.)

Visit www.id-extras.com for powerful InDesign scripts that save hours of work — automation, batch tools, and workflow boosters for serious designers.