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"];
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
...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
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
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"];
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
Copy link to clipboard
Copied
Thanks, Uwe:
I didn't know the correct terms to use.
Very helpful.
Larry
Copy link to clipboard
Copied
Hi Larry,
check DOM documentation for InDesign.
For CS6 and below I recommend Jongware's here:
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
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
Copy link to clipboard
Copied
use fit to frame option,
textframe.fit(FitOptions.FILL_PROPORTIONALLY);
textframe.fit(FitOptions.frameToContent);