Photoshop CS2
Adobe Photoshop CS2 Scripting Guide
Scripting basics 16
To assign a value to a variable, you use the equals sign (=), as follows:
thisNumber = 10
thisString = "Hello, World"
Note:
Remember to enclose string values in straight, double quotes ("").
Another rule of thumb for proper scripting in VBScript is to declare all of your variables somewhere near
the beginning of the script. That way you can easily see which variables are in use without having to search
throughout the script for them.
The VBScript tool
Option Explicit
forces you to declare all variables before you use them in a script
statement. It also helps you avoid situations in which you try to use a misspelled variable name or an
undeclared variable. You use
Option Explicit
before you declare any variables, as in the following
code sample:
Option Explicit
Dim thisNumber
Dim thisString
thisNumber = 10
thisString = "Hello, World"
Assigning an Object Reference as a Value
You assign an object reference as the value of a variable, use the
Set
command as well as the equal sign.
The following example uses
Set
and the
Add
method to create the variable
thisLayer
, create a new
Art
Layer
object, and then assign the new
Art Layer
object as the value of
thisLayer
:
Dim thisLayer
Set thisLayer = AppRef.Documents(0).ArtLayers.Add
The next example uses
Set
to assign an existing
Art Layer
object (in this case, the third
Art Layer
object added to the script) as the value of
thisLayer
:
Dim thisLayer
Set thisLayer =AppRef.Documents(0).ArtLayers(2)
Using the Variable in a Script Statement
When you use variables in your script to represent values, you use only the variable name without the
Dim
or
Set
keyword. The following example rotates the selected section of the
Art Layer
object
represented by the variable
thisLayer
by 45 degrees:
thisLayer.Selection.Rotate(45)
VBScript Value Types
You can use the following types of values for variables in VBScript.
Note:
For now, don’t worry about the value types you don’t understand.
Value Type
What It Is
Example
Boolean
Logical true or false
true
false
Empty
The variable holds no data
myVar = Empty
Error
Stores an error number
Null
The variable holds no valid
value (Usually used to test
an error condition)
null
Number
Any number not inside
double quotes
3.7
2000
Содержание PHOTOSHOP CS 2.0 - SCRIPTING GUIDE
Страница 1: ...bbc Adobe Photoshop cs 2 Scripting Guide ...