Adobe 23101764 Scripting Guide - Page 42

VBScript

Page 42 highlights

Scripting Photoshop 3 Your first Photoshop script 3.3.3 VBScript You don't need to use Visual Basic to run scripts on Windows. Another way to script Photoshop is to use a VBA editor (such as the one that is included in Microsoft Word) or to use Windows Scripting Host. Most Windows systems include Windows Scripting Host. If you do not have Windows Scripting Host or would like more information about Windows Scripting Host visit the Microsoft Windows Script Technologies Web site at http://msdn.microsoft.com/scripting/. VBScript considerations Both VBA and Windows Scripting Host use VBScript as their scripting language. The syntax for VBScript is very similar to the Visual Basic syntax. The three main differences relating to the scripts shown in this guide are: - VBScript is not as strongly typed as Visual basic. In Visual Basic you say: Dim aRef as Photoshop.ArtLayer in VBScript you say: Dim aRef For VBScript simply omit the "as" and everything that comes after the "as" (in this case Photoshop.ArtLayer). - VBScript does not support the "as New Photoshop.Application" form. In Visual Basic you can retrieve the Application object as: Dim appRef as New Photoshop.Application In VBScript you write the following to retrieve the Application object: Dim appRef Set appRef = CreateObject("Photoshop.Application") - VBScript does not support enumerations. Here's an example of how to set the extension type that can later be used to save a document. Dim extType As Photoshop.PsExtensionType extType = psUppercase In Visual Basic, the values of the various enumerations are specified in a parenthesis after the enumeration name. For an enumeration value such as "psTextLayer (2)", you would typically use the term "psTextLayer" (rather than "2") to refer to the kind of layer being described. For example: artLayerRef.Kind = psTextLayer VBScript, however, has no access to a type library; consequently, only the enumeration value "2" can be used -- not the term "psTextLayer". For example: artLayerRef.Kind = 2 Photoshop CS Scripting Guide 38

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105

Photoshop CS Scripting Guide
38
Scripting Photoshop
Your first Photoshop script
3
3.3.3 VBScript
You don't need to use Visual Basic to run scripts on Windows. Another way to script
Photoshop is to use a VBA editor (such as the one that is included in Microsoft Word) or to use
Windows Scripting Host.
Most Windows systems include Windows Scripting Host. If you do not have Windows
Scripting Host or would like more information about Windows Scripting Host visit the
Microsoft Windows Script Technologies Web site at http://msdn.microsoft.com/scripting/.
VBScript considerations
Both VBA and Windows Scripting Host use VBScript as their scripting language. The syntax
for VBScript is very similar to the Visual Basic syntax. The three main differences relating to
the scripts shown in this guide are:
VBScript is not as strongly typed as Visual basic. In Visual Basic you say:
Dim aRef as Photoshop.ArtLayer
in VBScript you say:
Dim aRef
For VBScript simply omit the “as” and everything that comes after the "as" (in this case
Photoshop.ArtLayer).
VBScript does not support the “as New Photoshop.Application” form.
In Visual Basic you can retrieve the Application object as:
Dim appRef as New Photoshop.Application
In VBScript you write the following to retrieve the Application object:
Dim appRef
Set appRef = CreateObject("Photoshop.Application")
VBScript does not support enumerations. Here's an example of how to set the extension
type that can later be used to save a document.
Dim extType As Photoshop.PsExtensionType
extType = psUppercase
In Visual Basic, the values of the various enumerations are speci
ed in a parenthesis
after the enumeration name. For an enumeration value such as “psTextLayer (2)”, you
would typically use the term “psTextLayer” (rather than "2") to refer to the kind of layer
being described. For example:
artLayerRef.Kind = psTextLayer
VBScript, however, has no access to a type library; consequently, only the enumeration
value "2" can be used -- not the term “psTextLayer”. For example:
artLayerRef.Kind = 2