Javascript - Adobe 65024872 - InDesign CS4 - Mac Manual

Scripting guide
Hide thumbs Also See for 65024872 - InDesign CS4 - Mac:
Table of Contents

Advertisement

Adobe InDesign CS4 Scripting Tutorial
--Resize the frame to a specific size.
set geometric bounds of myFrame to {0, 0, 144, 144}
--Fit the graphic to the frame proportionally.
fit myFrame given proportionally
--Next, fit frame to the resized graphic.
fit myFrame given frame to content
set myBounds to geometric bounds of myFrame
set myGraphicWidth to (item 4 of myBounds) - (item 2 of myBounds)
--Move the graphic frame.
set myPageWidth to page width of document preferences of myDocument
set myMarginPreferences to margin preferences of page 1 of myDocument
set myTopMargin to top of myMarginPreferences
move myFrame to {myPageWidth - myGraphicWidth, myTopMargin}
--Apply a text wrap to the graphic frame.
set text wrap type of text wrap preferences of myFrame to bounding box text wrap
set text wrap offset of text wrap preferences of myFrame to {24, 12, 24, 12}
end if
end tell

JavaScript

//Display a standard open file dialog box to select a graphic 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)){
var myGraphic = myDocument.pages.item(0).place(myGraphicFile);
//Since you can place multiple graphics at once, the place method
//returns an array. To get the graphic you placed, get the first
//item in the array (JavaScript arrays start with item 0).
myGraphic = myGraphic[0];
//Create an object style to apply to the graphic frame.
var myObjectStyle = myDocument.objectStyles.item("GraphicFrame");
try {
var myName = myObjectStyle.name;
}
catch (myError){
//The object style did not exist, so create it.
myObjectStyle = myDocument.objectStyles.add({name:"GraphicFrame"});
}
myObjectStyle.enableStroke = true;
myObjectStyle.strokeWeight = 3;
myObjectStyle.strokeType = myDocument.strokeStyles.item("Solid");
myObjectStyle.strokeColor = myDocument.colors.item("Red");
//The frame containing the graphic is the parent of the graphic.
var myFrame = myGraphic.parent;
myFrame.applyObjectStyle(myObjectStyle, true);
//Resize the frame to a specific size.
myFrame.geometricBounds = [0,0,144,144];
//Fit the graphic to the frame proportionally.
myFrame.fit(FitOptions.proportionally);
//Next, fit frame to the resized graphic.
myFrame.fit(FitOptions.frameToContent);
var myBounds = myFrame.geometricBounds;
var myGraphicWidth = myBounds[3]-myBounds[1];
Constructing a document 42

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs4

Table of Contents