Adobe 23101335 Scripting Guide - Page 43

Visual Basic and JavaScript, Set docRef = appRef.Documents.Add4

Page 43 highlights

Scripting Photoshop 3 Object references 3.4.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 To do a similar thing in JavaScript you could do: // set ruler units and create new document originalRulerUnits = preferences.rulerUnits preferences.rulerUnits = Units.INCHES; documents.add(4,4,72,"My New Document"); docRef = activeDocument; layer1Ref = docRef.artLayers.add(); layer2Ref = docRef.artLayers.add(); layer1Ref.name = "This layer was first"; // restore unit setting preferences.rulerUnits = originalRulerUnits; Photoshop 7.0 Scripting Guide 43

  • 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

Photoshop 7.0 Scripting Guide
43
Scripting Photoshop
Object references
3
3.4.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
To do a similar thing in JavaScript you could do:
// set ruler units and create new document
originalRulerUnits = preferences.rulerUnits
preferences.rulerUnits = Units.INCHES;
documents.add(4,4,72,"My New Document");
docRef = activeDocument;
layer1Ref = docRef.artLayers.add();
layer2Ref = docRef.artLayers.add();
layer1Ref.name = "This layer was first";
// restore unit setting
preferences.rulerUnits = originalRulerUnits;