Adobe 23102480 Scripting Guide - Page 65

> Script > HelloWorldDoc, Adobe Photoshop CS3 Visual Basic Scripting Reference

Page 65 highlights

Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Scripting Photoshop CS3 65 'use the Kind property of the Art Layers class to 'make the layer a text layer newTextLayer.Kind = 2 newTextLayer.TextItem.Contents = helloWorldStr newTextLayer.TextItem.Position = Array(0.75, 1) newTextLayer.TextItem.Size = 36 newTextLayer.TextItem.Color = textColor 2. Run the complete script. Be patient while Photoshop CS3 executes your commands one by one. 3. After viewing the document in Photoshop CS3, close the document without saving it. Note: Look up the following classes in the Adobe Photoshop CS3 Visual Basic Scripting Reference, or in the Visual Basic Object Browser to see if you understand how you used them in this script: ● SolidColor ● ArtLayer JS ➤ To create and specify details in a text item: 1. Type the following code into the HelloWorldDoc script immediately before the statements at the end of the file that restore original preferences. //create a reference to the active document docRef = app.activeDocument //create a variable named textColor //create a SolidColor object whose color is red //assign the object to textColor textColor = new solidColor textColor.rgb.red = 255 textColor.rgb.green = 0 textColor.rgb.blue = 0 helloWorldText = "Hello, World!" //create a variable named newTextLayer //use the add() method of the artLayers class to create a layer object //assign the object to newTextLayer newTextLayer = docRef.artLayers.add() //use the kind property of the artLayer class to make the layer a text layer newTextLayer.kind = LayerKind.TEXT newTextLayer.textItem.contents = helloWorldText newTextLayer.textItem.position = Array(0.75, 1) newTextLayer.textItem.size = 36 newTextLayer.textItem.color = textColor 2. Save the script, and then open Photoshop CS3 and select the script from the Scripts menu (choose File > Script > HelloWorldDoc). Be patient while Photoshop CS3 executes your commands one by one. 3. After viewing the document in Photoshop CS3, close Photoshop CS3 without saving the document.

  • 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
Scripting Photoshop CS3
65
'use the Kind property of the Art Layers class to
'make the layer a text layer
newTextLayer.Kind = 2
newTextLayer.TextItem.Contents = helloWorldStr
newTextLayer.TextItem.Position = Array(0.75, 1)
newTextLayer.TextItem.Size = 36
newTextLayer.TextItem.Color = textColor
2.
Run the complete script. Be patient while Photoshop CS3 executes your commands one by one.
3.
After viewing the document in Photoshop CS3, close the document without saving it.
Note:
Look up the following classes in the
Adobe Photoshop CS3 Visual Basic Scripting Reference
, or in the
Visual Basic Object Browser to see if you understand how you used them in this script:
SolidColor
ArtLayer
JS
To create and specify details in a text item:
1.
Type the following code into the
HelloWorldDoc
script immediately before the statements at the end
of the file that restore original preferences.
//create a reference to the active document
docRef = app.activeDocument
//create a variable named textColor
//create a SolidColor object whose color is red
//assign the object to textColor
textColor = new solidColor
textColor.rgb.red = 255
textColor.rgb.green = 0
textColor.rgb.blue = 0
helloWorldText = "Hello, World!"
//create a variable named newTextLayer
//use the add() method of the artLayers class to create a layer object
//assign the object to newTextLayer
newTextLayer = docRef.artLayers.add()
//use the kind property of the artLayer class to make the layer a text layer
newTextLayer.kind = LayerKind.TEXT
newTextLayer.textItem.contents = helloWorldText
newTextLayer.textItem.position = Array(0.75, 1)
newTextLayer.textItem.size = 36
newTextLayer.textItem.color = textColor
2.
Save the script, and then open Photoshop CS3 and select the script from the Scripts menu (choose
File
> Script > HelloWorldDoc
). Be patient while Photoshop CS3 executes your commands one by one.
3.
After viewing the document in Photoshop CS3, close Photoshop CS3 without saving the document.