Adobe 23101764 Scripting Guide - Page 60

Visual Basic and JavaScript

Page 60 highlights

Scripting Photoshop 3 Object references 3. set newDocument to make new document with properties ¬ { width: inches 2, height: inches 3} 4. set layerRef to layer 1 of current document 5. make new art layer in current document 6. set name of layerRef to "My layer" 7. end tell This script will not set the name of the layer referenced on the fourth line of the script. Instead it will set the name created on line five. Try referencing the objects by name as shown below: 1. tell application "Adobe Photoshop CS" 2. activate 3. set newDocument to make new document with properties ¬ { width: inches 2, height: inches 3} 4. make new art layer in current document with properties {name: "L1" } 5. make new art layer in current document with properties {name: "L2" } 6. set name of art layer "L1" of current document to "New Layer 1" 7. end tell 3.5.2 Visual Basic and JavaScript Object references in Visual Basic and JavaScript are fixed and remain valid until disposed or until the host object goes away. The following example shows how to create 2 layers and then rename the first one in Visual Basic. Dim appRef As Photoshop.Application Dim docRef As Photoshop.Document Dim layer1Ref As Photoshop.ArtLayer Dim layer2Ref As Photoshop.ArtLayer ' Set ruler units and create a new document. Set appRef = New Photoshop.Application originalRulerUnits = appRef.Preferences.RulerUnits appRef.Preferences.RulerUnits = psInches Set docRef = appRef.Documents.Add(4, 4, 72, "My New Document") ' Create 2 new layers and store their return references. Set layer1Ref = docRef.ArtLayers.Add() Set layer2Ref = docRef.ArtLayers.Add() ' Change the name of the first layer that was created. layer1Ref.Name = "This layer was first" 'restore unit values appRef.Preferences.RulerUnits = originalRulerUnits Photoshop CS Scripting Guide 56

  • 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
56
Scripting Photoshop
Object references
3
3.
set newDocument to make new document with properties ¬
{ width: inches 2, height: inches 3}
4.
set layerRef to layer 1 of current document
5.
make new art layer in current document
6.
set name of layerRef to "My layer"
7.
end tell
This script will not set the name of the layer referenced on the fourth line of the script. Instead
it will set the name created on line
ve. Try referencing the objects by name as shown below:
1.
tell application "Adobe Photoshop CS"
2.
activate
3.
set newDocument to make new document with properties ¬
{ width: inches 2, height: inches 3}
4.
make new art layer in current document with properties {name: "L1" }
5.
make new art layer in current document with properties {name: "L2" }
6.
set name of art layer "L1" of current document to "New Layer 1"
7.
end tell
3.5.2
Visual Basic and JavaScript
Object references in Visual Basic and JavaScript are
xed and remain valid until disposed or
until the host object goes away.
The following example shows how to create 2 layers and then rename the
rst one in Visual
Basic.
Dim appRef As Photoshop.Application
Dim docRef As Photoshop.Document
Dim layer1Ref As Photoshop.ArtLayer
Dim layer2Ref As Photoshop.ArtLayer
' Set ruler units and create a new document.
Set appRef = New Photoshop.Application
originalRulerUnits = appRef.Preferences.RulerUnits
appRef.Preferences.RulerUnits = psInches
Set docRef = appRef.Documents.Add(4, 4, 72, "My New Document")
' Create 2 new layers and store their return references.
Set layer1Ref = docRef.ArtLayers.Add()
Set layer2Ref = docRef.ArtLayers.Add()
' Change the name of the first layer that was created.
layer1Ref.Name = "This layer was first"
'restore unit values
appRef.Preferences.RulerUnits = originalRulerUnits