Operators; Methods - Adobe 27510753 - InDesign CS2 - PC Manual

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

Advertisement

14
Scripting Basics
for(myCounter = 0; myCounter < app.activeDocument.pages.item(0).pageItems.length; myCounter ++){
var myPageItem = app.activeDocument.pages.item(0).pageItems.item(myCounter);
var myPageItemType = myPageItem.getElements()[0].constructor.name;
alert(myPageItemType);
}

Operators

Operators use variables or values to perform calculations (addition, subtraction, multiplication, and division)
and return a value. For example:
MyWidth/2
returns a value equal to half of the content of the variable myWidth .
You can also use operators to perform comparisons (equal to (=), not equal to(<>), greater than(>), or less
than(<)). For example:
MyWidth > myHeight
returns the value true (or 1) if myWidth is greater than myHeight , or false (0), if it isn't.
All the scripting languages provide additional utility operators. In AppleScript and VBScript, the ampersand
(&) concatenates (or joins) two strings:
"Pride " & "and Prejudice"
returns the string:
"Pride and Prejudice"
In JavaScript, use a plus sign (+) to join the two strings:
"Pride " + "and Prejudice"
//returns the string: "Pride and Prejudice"

Methods

Methods (sometimes called commands or events) are the verbs of scripting. They're the parts of the script that
make more-complex things happen than can be achieved simply by assigning property values. The type of
the object you're working with determines the quantity and type of methods that you can use to manipulate
the object.
In AppleScript, the make command creates new objects, while set assigns values to properties or creates
object variables. In VBScript, the Add method creates new objects, the Set statement assigns InDesign
objects to VBScript variables, and the equal sign (=) assigns property values (in Visual Basic.NET, you can omit
the Set ). In JavaScript, the add() method creates new objects, and the equal sign (=) assigns objects to a
variable.
If you use more than one scripting language, it's easy to get confused as you switch among them. When
you're using AppleScript, remember that the equal sign is used only in logical statements ( If ) and that set is
used for all variable assignments. When you're using VBScript or Visual Basic (versions other than VB.NET), Set
is used only when you are creating an object variable. In JavaScript, the equal sign is used for assigning values
to a variable; use a double equal sign (==) to compare objects.
Parameters are sometimes required; for example, when you create a group, InDesign needs to know which
objects to include in the new group. Other parameters are optional; for example, when you create a new
document, you can specify that InDesign base the new document on a document preset, but it's not required.
Adobe InDesign CS2 Scripting Guide

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs2

Table of Contents