Adobe 23101764 Scripting Guide - Page 60
Visual Basic and JavaScript
UPC - 718659340025
View all Adobe 23101764 manuals
Add to My Manuals
Save this manual to your list of manuals |
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