Skip to main content
Participant
October 2, 2019
Answered

Adjust frameFittingOptions on PlaceGun

  • October 2, 2019
  • 3 replies
  • 756 views

I would like the images that I'm dragging into InDesign to be contained in the frame, when dropped in one.

I have tried things like 

app.activeDocument.frameFittingOptions.fittingOnEmptyFrame = EmptyFrameFittingOptions.PROPORTIONALLY;

in the function where I use the placeGun, but nothing seems to work. Am I missing something? 

This topic has been closed for replies.
Correct answer Laubender

Hi CCIntera,

if you want no user interaction you'll need a startup script.

With an event listener that registers on afterPlace.

 

The following script snippet is not the real solution because it will register the event listener on the active document. So it cannot used as startup script, but it's a starting point you can work with.

 

FWIW: Always check the nature of event.target before doing something.

In case a placegun is loaded with an image and unloaded to a graphic frame the target becomes that graphic frame.

 

#targetengine "afterPlaceAGraphicToActiveDocument"

var myDoc=app.documents[0];

myDoc.addEventListener( "afterPlace" , fitGraphicContents );

function fitGraphicContents( event )
{
	var myTarget = event.target;
	myTarget.fit( FitOptions.CONTENT_TO_FRAME );
};

 

See into all options with method fit() in the DOM description for ExtendScript:

https://www.indesignjs.de/extendscriptAPI/indesign14/#FitOptions.html

 

Regards,
Uwe Laubender

( ACP )

3 replies

Community Expert
October 5, 2019

Hi CCIntera,

I do not know any details of your intended script so maybe you could use my snippet in my last reply nearly as is.

Note: You could also add the eventlistener to a graphic frame in your document. That would be the minimal invasive thing…

 

Regards,
Uwe Laubender

( ACP )

LaubenderCommunity ExpertCorrect answer
Community Expert
October 5, 2019

Hi CCIntera,

if you want no user interaction you'll need a startup script.

With an event listener that registers on afterPlace.

 

The following script snippet is not the real solution because it will register the event listener on the active document. So it cannot used as startup script, but it's a starting point you can work with.

 

FWIW: Always check the nature of event.target before doing something.

In case a placegun is loaded with an image and unloaded to a graphic frame the target becomes that graphic frame.

 

#targetengine "afterPlaceAGraphicToActiveDocument"

var myDoc=app.documents[0];

myDoc.addEventListener( "afterPlace" , fitGraphicContents );

function fitGraphicContents( event )
{
	var myTarget = event.target;
	myTarget.fit( FitOptions.CONTENT_TO_FRAME );
};

 

See into all options with method fit() in the DOM description for ExtendScript:

https://www.indesignjs.de/extendscriptAPI/indesign14/#FitOptions.html

 

Regards,
Uwe Laubender

( ACP )

CCInteraAuthor
Participant
October 7, 2019
The script you provided works flawlessly. Thanks a lot!
Bill Silbert
Community Expert
Community Expert
October 2, 2019

With no document open go to Object>Fitting>Frame Fitting Options... 

You will then get the Frame Fitting Options dialog in which you'll choose "Fit Content Proportionally" from the Fitting: drop-down menu. Then quit the program. When you relaunch InDesign this will become the default for graphic frames.

CCInteraAuthor
Participant
October 2, 2019
Unfortunately, I'm looking for a script-side solution that does not require any user input. Thank you for your answer, though!