Adobe 27510753 Scripting Guide - Page 20
Array variables, Converting values from one type to another, AppleScript
UPC - 718659445294
View all Adobe 27510753 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 20 highlights
12 Scripting Basics Adobe InDesign CS2 Scripting Guide Like VB.NET, JavaScript does not require Set when you assign values to variables, regardless of the type of the variable: var myDocument = app.documents.add(); var myString = "X"; Array variables AppleScript, VBScript, and JavaScript all support arrays, which is a variable type that is a list of values. In AppleScript, an array is called a list. AppleScript set myArray to {1, 2, 3, 4} VBScript JavaScript myArray = Array(1, 2, 3, 4) Rem In Visual Basic.NET: myArray = New Double (1, 2, 3, 4) myArray = [1, 2, 3, 4]; To refer to an item in an array, refer to the item by its index in the array. The first item in an array in VBScript and JavaScript is item 0; in AppleScript, the first item in an array is item 1. AppleScript VBScript JavaScript set myFirstArrayItem to item 1 of myArray myFirstArrayItem = myArray(0) myFirstArrayItem = myArray[0]; Note: The Visual Basic Option Base statement can be used to set the first item of an array to item 1. The examples in this book and on your InDesign CD assume that the first item in an array is item 0, not item 1, because that is the default. If you have set the Option Base to 1, you must adjust all the array references in the example scripts accordingly. Arrays can include other arrays, as shown in the following examples. AppleScript VBScript JavaScript set myArray to {{0, 0}, {72, 72}} myArray = Array(Array(0,0), Array(72, 72)) Rem In Visual Basic.NET: myArray = New Array(New Double(0,0), NewDouble (0,0)) myArray = [[0,0], [72,72]]; Converting values from one type to another All the scripting languages supported by InDesign provide ways to convert variable values from one type to another. The most common conversions involve converting numbers to strings (so that you can enter them in text or display them in dialog boxes) or converting strings to numbers (so that you can use them to set a point size or other numeric values). AppleScript --To convert from a number to a string: set myNumber to 2 set myString to (myNumber as string) --To convert from a string to a number: set myString to "2" set myNumber to (myString as integer) --if your string contains a decimal value, use "as real" rather than "as integer"