Adobe 23102480 Scripting Guide - Page 16

Creating and Running a VBScript, To create and run your first Photoshop CS3 VBScript

Page 16 highlights

Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Photoshop CS3 Scripting Basics 16 Note: The lines preceded by "--" are comments. Entering the comments is optional. -- Sample script to create a new text item and -- change its contents. --target Photoshop CS3 tell application "Adobe Photoshop CS3" -- Create a new document and art layer. set docRef to make new document with properties ¬ {width:4 as inches, height:2 as inches} set artLayerRef to make new art layer in docRef -- Change the art layer to be a text layer. set kind of artLayerRef to text layer -- Get a reference to the text object and set its contents. set contents of text object of artLayerRef to "Hello, World" end tell 2. Click Run to run the script. Photoshop CS3 creates a new document, adds a new layer, changes the layer's type to text and sets the text to "Hello, World" Note: If you encounter errors, refer to Introduction to Scripting, which has a section on AppleScript debugging. Creating and Running a VBScript Follow these steps to create and run a VBScript that displays the text Hello World! in a Photoshop CS3 document. ➤ To create and run your first Photoshop CS3 VBScript: 1. Type the following script into a script or text editor. Note: Entering comments is optional. Dim appRef Set appRef = CreateObject( "Photoshop.Application" ) ' Remember current unit settings and then set units to ' the value expected by this script Dim originalRulerUnits originalRulerUnits = appRef.Preferences.RulerUnits appRef.Preferences.RulerUnits = 2 ' Create a new 2x4 inch document and assign it to a variable. Dim docRef Dim artLayerRef Dim textItemRef Set docRef = appRef.Documents.Add(2, 4) ' Create a new art layer containing text Set artLayerRef = docRef.ArtLayers.Add artLayerRef.Kind = 2 ' Set the contents of the text layer. Set textItemRef = artLayerRef.TextItem textItemRef.Contents = "Hello, World!" ' Restore unit setting

  • 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

Photoshop CS3
Adobe Photoshop CS3
Scripting Guide
Photoshop CS3 Scripting Basics
16
Note:
The lines preceded by “--” are comments. Entering the comments is optional.
-- Sample script to create a new text item and
-- change its contents.
--target Photoshop CS3
tell application "Adobe Photoshop CS3"
-- Create a new document and art layer.
set docRef to make new document with properties ¬
{width:4 as inches, height:2 as inches}
set artLayerRef to make new art layer in docRef
-- Change the art layer to be a text layer.
set kind of artLayerRef to text layer
-- Get a reference to the text object and set its contents.
set contents of text object of artLayerRef to "Hello, World"
end tell
2.
Click
Run
to run the script. Photoshop CS3 creates a new document, adds a new layer, changes the
layer’s type to text and sets the text to “Hello, World”
Note:
If you encounter errors, refer to
Introduction to Scripting
, which has a section on AppleScript
debugging.
Creating and Running a VBScript
Follow these steps to create and run a VBScript that displays the text
Hello World!
in a Photoshop CS3
document.
To create and run your first Photoshop CS3 VBScript:
1.
Type the following script into a script or text editor.
Note:
Entering comments is optional.
Dim appRef
Set appRef = CreateObject( "Photoshop.Application" )
' Remember current unit settings and then set units to
' the value expected by this script
Dim originalRulerUnits
originalRulerUnits = appRef.Preferences.RulerUnits
appRef.Preferences.RulerUnits = 2
' Create a new 2x4 inch document and assign it to a variable.
Dim docRef
Dim artLayerRef
Dim textItemRef
Set docRef = appRef.Documents.Add(2, 4)
' Create a new art layer containing text
Set artLayerRef = docRef.ArtLayers.Add
artLayerRef.Kind = 2
' Set the contents of the text layer.
Set textItemRef = artLayerRef.TextItem
textItemRef.Contents = "Hello, World!"
' Restore unit setting