Variables - Adobe 27510753 - InDesign CS2 - PC Manual

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

Advertisement

10
Scripting Basics
Value type
Double (VBScript),
fixed or real (Apple-
Script), floating point
(JavaScript)
String
Array (VBScript,
JavaScript)
or list (AppleScript)

Variables

Variables are containers for data. A variable might hold a number, a string of text, or a reference to an
InDesign object. Variables have names, and you refer to a variable by its name. To put data into a variable, you
assign the data to the variable. The file name of the current InDesign publication, the current date and time,
and the number of pages in the publication are all examples of data that you can assign to a variable.
Why not simply enter the data itself (the publication's name, or the current date and time, or the number of
pages in the publication, for example), rather than using variables? Because, if you do, your script will work
in only one publication or situation. By using variables, you can write scripts that will work in a wider range
of situations. As a script executes, it can assign data to the variables that reflect the current publication and
selection (for example), and then make decisions based on the content of the variables.
Assigning values or strings to variables is fairly simple, as shown in the following examples.
AppleScript
VBScript
JavaScript
In AppleScript, you can assign an object reference to a variable as you create the object:
set myTextFrame to make text frame with properties(geometric bounds: (0,0,3.5, 4))
or you can fill the variable with a reference to an existing object:
tell application "Adobe InDesign CS2"
set myTextFrame to first text frame of the first spread of the first document
end tell
VBScript works in a similar way. For example, to assign a variable as you create a frame ( myInDesign in the
following line is a reference to the InDesign application object):
Set myTextFrame = myInDesign.Documents.Item(1).Spreads.Item(1).TextFrames.Add
or to refer to an existing frame:
Set myTextFrame = InDesign.Documents.Item(1).Spreads.Item(1).TextFrames.Item(1)
What it is
A high-precision number that can con-
tain a decimal point.
A series of text characters. Strings ap-
pear inside (straight) quotation marks.
A list of values (the values can be any
type).
set myNumber to 10
set myString to "Hello, World!"
myNumber = 10
myString = "Hello, World!"
var myNumber = 10;
var myString = "Hello, World!";
Adobe InDesign CS2 Scripting Guide
Example
13.9972
"I am a string"
AppleScript: {"0p0", "0p0",
"16p4", "20p6"}
VBScript: Array("0p0", "0p0",
"16p4", "20p6")
JavaScript: ["0p0", "0p0", "16p4",
"20p6"]

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs2

Table of Contents