Adobe 65014293 Scripting Guide - Page 39

Working with Layer Set objects

Page 39 highlights

CHAPTER 3: Scripting Photoshop Working with the Photoshop Object Model 39 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 NOTE: Unlike object references in JavaScript or VBScript, AppleScript object reference names do not remain constant. Refer to an AppleScript language guide or text book for information on referencing a file using either as alias or to a reference to file. VBS Layers("Layer 3").name JS layers["Layer 3"].name //using the collection name and square brackets for the collection Working with Layer Set objects AS VBS JS Existing layers can be moved into layer sets. The following examples show how to create a Layer Set object, duplicate an existing ArtLayer object, and move the duplicate object into the layer set. set current document to document "My Document" set layerSetRef to make new layer set at end of current document set newLayer to duplicate layer "Layer 1" of current document ¬ to end of current document move newLayer to end of layerSetRef In AppleScript, you can also duplicate a layer directly into the destination layer set. set current document to document "My Document" set layerSetRef to make new layer set at end of current document duplicate layer "Layer 1" of current document to end of layerSetRef In VBScript you can duplicate and place the layer with the same method. Dim appRef, docRef Set appRef = CreateObject("Photoshop.Application") 'Make a new document and a first layer in the document Set docRef = appRef.Documents.Add() appRef.ActiveDocument.ArtLayers.Add() Set layerSetRef = docRef.LayerSets.Add() Set layerRef = docRef.ArtLayers(1).Duplicate(layerSetRef, 2) In JavaScript you can place the layer during the duplication method. // create a document and an initial layer var docRef = app.documents.add() docRef.artLayers.add() var layerSetRef = docRef.layerSets.add() var layerRef = docRef.artLayers[0].duplicate(layerSetRef, ElementPlacement.PLACEATEND)

  • 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

C
HAPTER
3: Scripting Photoshop
Working with the Photoshop Object Model
39
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
N
OTE
:
Unlike object references in JavaScript or VBScript, AppleScript object reference names do not
remain constant. Refer to an AppleScript language guide or text book for information on referencing a file
using either
as
alias
or
to
a
reference
to
file
.
VBS
Layers("Layer 3").name
JS
layers["Layer 3"].name //using the collection name and square brackets for the collection
Working with Layer Set objects
Existing layers can be moved into layer sets. The following examples show how to create a
Layer Set
object, duplicate an existing
ArtLayer
object, and move the duplicate object into the layer set.
AS
set current document to document "My Document"
set layerSetRef to make new layer set at end of current document
set newLayer to duplicate layer "Layer 1" of current document ¬
to end of current document
move newLayer to end of layerSetRef
In AppleScript, you can also duplicate a layer directly into the destination layer set.
set current document to document "My Document"
set layerSetRef to make new layer set at end of current document
duplicate layer "Layer 1" of current document to end of layerSetRef
VBS
In VBScript you can duplicate and place the layer with the same method.
Dim appRef, docRef
Set appRef = CreateObject("Photoshop.Application")
'Make a new document and a first layer in the document
Set docRef = appRef.Documents.Add()
appRef.ActiveDocument.ArtLayers.Add()
Set layerSetRef = docRef.LayerSets.Add()
Set layerRef = docRef.ArtLayers(1).Duplicate(layerSetRef, 2)
JS
In JavaScript you can place the layer during the duplication method.
// create a document and an initial layer
var docRef = app.documents.add()
docRef.artLayers.add()
var layerSetRef = docRef.layerSets.add()
var layerRef = docRef.artLayers[0].duplicate(layerSetRef,
ElementPlacement.PLACEATEND)