Subroutines And Handlers - Adobe 27510753 - InDesign CS2 - PC Manual

Scripting guide
Hide thumbs Also See for 27510753 - InDesign CS2 - PC:
Table of Contents

Advertisement

Adobe InDesign CS2 Scripting Guide
VBScript
Here is a simple loop:
For counter = 1 to 20
Rem do something
Next
Here is a conditional loop:
Do While myStop = false
Rem do something, at some point setting myStop to true to leave the loop.
loop
JavaScript
Here is a simple loop:
for(var myCounter = 0; myCounter < 20; myCounter++){
//do something
}
Here is a conditional loop:
while (myStop == false){
//do something, at some point setting myStop to true to leave the loop.
}

Subroutines and handlers

Subroutines and functions (in VBScript or JavaScript) or handlers (in AppleScript) are scripting modules that
you can refer to from within your script. (In VBScript, the main difference between subroutines and functions
is that a function returns a value; a subroutine does not.) Typically, you send a value or series of values to a
subroutine (or handler), and get back some other value or values. There's nothing special about the code used
in subroutines and handlers; they're simply conveniences to avoid typing the same lines of code over and
over in your script. If you find yourself typing or pasting the same lines of code into several different places in
a script, you've identified a good candidate for a subroutine or handler.
AppleScript
--Calculate the geometric center of a selected page item
--Assumes you have a single page item selected.
tell application "Adobe InDesign CS2"
set mySelection to item 1 of selection
--Use "my" (or "of me") to specify a handler outside of the current "tell" context.
set myCenterPoint to my myCalculateCenterPoint(mySelection)
display dialog "x center: " & item 1 of myCenterPoint & return & "y center: " & item 2 of
myCenterPoint
end tell
--The following lines define the handler.
on myCalculateCenterPoint(myObject)
set myGeometricBounds to geometric bounds of myObject
set myX1 to item 2 of myGeometricBounds
set myY1 to item 1 of myGeometricBounds
set myX2 to item 4 of myGeometricBounds
set myY2 to item 3 of myGeometricBounds
set myXCenter to myX1 + ((myX2 - myX1) / 2)
set myYCenter to myY1 + ((myY2 - myY1) / 2)
return {myXCenter, myYCenter}
end myCalculateCenterPoint
Scripting Basics
17

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs2

Table of Contents