Adobe 23101764 Scripting Guide - Page 25
Using variables to store references, Naming variables
UPC - 718659340025
View all Adobe 23101764 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 25 highlights
Scripting basics 2 Variables 2.6.2 Using variables to store references Variables can also be used to store references to objects. In AppleScript, a reference is returned when you create a new object in an Photoshop document as shown below: set thisLayer to make new art layer in current document Or you can fill the variable with a reference to an existing object: set thisLayer to art layer 1 of current document Visual Basic works similarly, however, there is an important distinction to note. If you are assigning an object reference to a variable you must use the Set command. For example, to assign a variable as you create a layer, use Set: Set thisLayer = appRef.Photoshop.ActiveDocument.ArtLayers(1) or in reference to an existing layer, since it is also an object reference, use Set: Set thisLayer = appRef.Photoshop.ActiveDocument.ArtLayers(1) If you are trying to assign a value to a variable in Visual Basic that is not an object reference, do not use Set. Use Visual Basic's assignment operator, the equals sign: thisNumber = 12 JavaScript looks similar to Visual Basic. To assign a reference to an object, you would write: var docRef = app.activeDocument; and to assign a value use the following: var thisNumber = 12 2.6.3 Naming variables It's a good idea to use descriptive names for your variables-something like firstPage or corporateLogo, rather than x or c. You can also give your variable names a standard prefix so that they'll stand out from the objects, commands, and keywords of your scripting system. Variable names must be a single word, but you can use internal capitalization (such as myFirstPage) or underscore characters (my_first_page) to create more readable names. Variable names cannot begin with a number, and they can't contain punctuation or quotation marks. Photoshop CS Scripting Guide 21