• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Help with InDesign script to import and resize graphic

Explorer ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

Hello:

I'm new to scripting and could use some help with a script for importing a graphic, and then resizing the graphic to a specific size and adjusting the graphic placement.

Here is what I've got so far.

Sorry if it is primitive, but I not sure how to go forward.

The script "does" prompt to import the graphic, say, a stock report or comic graphic, and once selected, it imports it, but then gives an error message.

I wold like to resize the graphic to the sizes listed, fit content to frame, and position it with x, y coordinates.

Thanks for any help you can offer.

var myDocument = app.activeDocument, 

//Display a standard open file dialog box to select a raphic file. var myGraphicFile = File.openDialog("Choose a graphic file"); //If a graphic file was selected, and if you didn't press Cancel, //place the graphic file on the page. if((myGraphicFile != "")&&(myGraphicFile != null)){

myGraphicFile = File.openDialog("Choose a graphic file");

var myGraphic = myDocument.pages.item(0).place(myGraphicFile);

var g=app.activeDocument.allGraphics; 

  myGraphicFrame.geometricBounds = ["6p", "2.4p", "129p", "63.4p"];

TOPICS
Scripting

Views

2.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Aug 08, 2018 Aug 08, 2018

Looks like the result of the "place()" method is an array. A one-item array, so the image is going to be myGraphic[0]. To get the frame that contains myGraphic[0], ask for the "parent". Thus:

myGraphic[0].parent.geometricBounds = ["6p", "2.4p", "129p", "63.4p"];

Some advice you didn't ask for: If this script is going to be used by others, think about what happens if someone accidentally chooses something other than a graphic file at File.openDialog. You can add a filter to that command so that onl

...

Votes

Translate

Translate
Engaged ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

Looks like the result of the "place()" method is an array. A one-item array, so the image is going to be myGraphic[0]. To get the frame that contains myGraphic[0], ask for the "parent". Thus:

myGraphic[0].parent.geometricBounds = ["6p", "2.4p", "129p", "63.4p"];

Some advice you didn't ask for: If this script is going to be used by others, think about what happens if someone accidentally chooses something other than a graphic file at File.openDialog. You can add a filter to that command so that only specified file types are displayed.

Hope this helps.

Bob

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 09, 2018 Aug 09, 2018

Copy link to clipboard

Copied

Thanks, Bob:

It worked it moved it to where I need it to go.

Next question:

How to I get the graphic to fit...Content to Frame?

Plus, how do I set up the filters to only allow certain files?

Thanks so much for your help.

I greatly appreciate it..

Larry

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

hiiii larry,

for x, y  cordinate you can use move(), like this,

     myGraphic[0].parent.move(["2.4p", "6p"]);

and you can set gb of image and parent as well,

     myGraphic[0].geometricBounds = ["60", "20", "129", "63"];

    myGraphic[0].parent.geometricBounds = ["60", "20", "129", "63"];

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 09, 2018 Aug 09, 2018

Copy link to clipboard

Copied

Hi payalm68947498 ,

FWIW: Method move() with page items has two arguments.

The first one is to and the second one is by.

Both should be expressed as an array of [ x , y ] values.

If you want to move an object to a position use:

pageItem.move( [ x , y ] )

If you want to move an object by an amount of values:

pageItem.move( undefined , [ x , y ] )

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 09, 2018 Aug 09, 2018

Copy link to clipboard

Copied

Thanks, Uwe:

I didn't know the correct terms to use.

Very helpful.

Larry

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 10, 2018 Aug 10, 2018

Copy link to clipboard

Copied

LATEST

Hi Larry,

check DOM documentation for InDesign.

For CS6 and below I recommend Jongware's here:

Indesign JavaScript Help

With CC 2018 look into Gregor Fellenz' there:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#about.html

You'll find all available methods, properties and objects.

E.g. with TextFrame and its method fit() :

Adobe InDesign CS6 (8.0) Object Model JS: TextFrame

Options explained:

Adobe InDesign CS6 (8.0) Object Model JS: FitOptions

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 09, 2018 Aug 09, 2018

Copy link to clipboard

Copied

Thanks:

How do I scale the graphic once it moved into place.

I need it to Fit Content to Frame...but not sure of the terms to use.

Thanks again.

Larry

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 09, 2018 Aug 09, 2018

Copy link to clipboard

Copied

use fit to frame option,

textframe.fit(FitOptions.FILL_PROPORTIONALLY);

textframe.fit(FitOptions.frameToContent);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines