Adobe 13102498 Scripting Guide - Page 36

Referencing ArtLayer Objects

Page 36 highlights

Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Scripting Photoshop CS3 36 end tell VBS Dim appRef Set appRef = CreateObject("Photoshop.Application") 'Make a new document and a first layer in the document appRef.Documents.Add() appRef.ActiveDocument.ArtLayers.Add() ' Get a reference to the first layer in the document Dim layerRef Set layerRef = appRef.ActiveDocument.Layers(1) ' Create a new LayerSet (it will be created at the beginning of the document) Dim newLayerSetRef Set newLayerSetRef = appRef.ActiveDocument.LayerSets.Add ' Move the new layer to after the first layer newLayerSetRef.Move layerRef, 4 'psPlaceAfter JS // make a new document and a layer in the document app.documents.add() app.activeDocument.artLayers.add() // Get a reference to the first layer in the document var layerRef = app.activeDocument.layers[0] // Create a new LayerSet (it will be created at the beginning of the // document) var newLayerSetRef = app.activeDocument.layerSets.add() // Move the new layer to after the first layer newLayerSetRef.move(layerRef, ElementPlacement.PLACEAFTER) Referencing ArtLayer Objects When you create a layer in the Photoshop CS3 application (rather than a script), the layer is added to the Layers palette and given a number. These numbers act as layer names and do not correspond to the index numbers of ArtLayer objects you create in a script. Your script-VBScript or JavaScript-will always consider the layer at the top of the list in the Layers palette as the first layer in the index. For example, if your document has four layers, the Photoshop CS3 application names them Background Layer, Layer 1, Layer 2, and Layer 3. Normally, Layer 3 would be at the top of the list in the Layers palette because you added it last. If your script is working on this open document and uses the syntax Layers(1).Select/layers[0].select() to tell Photoshop CS3 to select a layer, Layer 3 is selected. If you then you drag the Background layer to the top of the list in the Layers palette and run the script again, the Background layer is selected. You can use the following syntax to refer to the layers by the names given them by the Application: AS layer 1 of layer set 1 of current 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
36
end tell
VBS
Dim appRef
Set appRef = CreateObject("Photoshop.Application")
'Make a new document and a first layer in the document
appRef.Documents.Add()
appRef.ActiveDocument.ArtLayers.Add()
' Get a reference to the first layer in the document
Dim layerRef
Set layerRef = appRef.ActiveDocument.Layers(1)
' Create a new LayerSet (it will be created at the beginning of the document)
Dim newLayerSetRef
Set newLayerSetRef = appRef.ActiveDocument.LayerSets.Add
' Move the new layer to after the first layer
newLayerSetRef.Move layerRef, 4 'psPlaceAfter
JS
// make a new document and a layer in the document
app.documents.add()
app.activeDocument.artLayers.add()
// Get a reference to the first layer in the document
var layerRef = app.activeDocument.layers[0]
// Create a new LayerSet (it will be created at the beginning of the // document)
var newLayerSetRef = app.activeDocument.layerSets.add()
// Move the new layer to after the first layer
newLayerSetRef.move(layerRef, ElementPlacement.PLACEAFTER)
Referencing ArtLayer Objects
When you create a layer in the Photoshop CS3 application (rather than a script), the layer is added to the
Layers palette and given a number. These numbers act as layer names and do not correspond to the index
numbers of
ArtLayer
objects you create in a script.
Your script—VBScript or JavaScript—will always consider the layer at the top of the list in the Layers
palette as the first layer in the index. For example, if your document has four layers, the Photoshop CS3
application names them Background Layer, Layer 1, Layer 2, and Layer 3. Normally, Layer 3 would be at the
top of the list in the Layers palette because you added it last. If your script is working on this open
document and uses the syntax
Layers(1).Select/layers[0].select()
to tell Photoshop CS3 to select
a layer, Layer 3 is selected. If you then you drag the Background layer to the top of the list in the Layers
palette and run the script again, the Background layer is selected.
You can use the following syntax to refer to the layers by the names given them by the Application:
AS
layer 1 of layer set 1 of current document