Adobe 23101335 Scripting Guide - Page 40

Set artLayerRef = docRef.ArtLayers.Add, Set appRef = CreateObject Photoshop.Application

Page 40 highlights

Scripting Photoshop 3 Your first Photoshop script Here's an example VBScript: ' Hello World Script Dim appRef Set appRef = CreateObject( "Photoshop.Application" ) ' Remember current unit settings and then set units to ' the value expected by this script Dim originalRulerUnits originalRulerUnits = appRef.Preferences.RulerUnits appRef.Preferences.RulerUnits = 2 ' Create a new 4x4 inch document and assign it to a variable. Dim docRef Dim artLayerRef Dim textItemRef Set docRef = appRef.Documents.Add(4, 4) ' Create a new art layer containing text Set artLayerRef = docRef.ArtLayers.Add artLayerRef.Kind = 2 ' Set the contents of the text layer. Set textItemRef = artLayerRef.TextItem textItemRef.Contents = "Hello, World!" ' Restore unit setting appRef.Preferences.RulerUnits = originalRulerUnits To run this script create a text file and copy the script into it. Save the file with a "vbs" extension. Double-click the file to execute. Photoshop 7.0 Scripting Guide 40

  • 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
40
Scripting Photoshop
Your first Photoshop script
3
Here’s an example VBScript:
' Hello World Script
Dim appRef
Set appRef = CreateObject( "Photoshop.Application" )
' Remember current unit settings and then set units to
' the value expected by this script
Dim originalRulerUnits
originalRulerUnits = appRef.Preferences.RulerUnits
appRef.Preferences.RulerUnits = 2
' Create a new 4x4 inch document and assign it to a variable.
Dim docRef
Dim artLayerRef
Dim textItemRef
Set docRef = appRef.Documents.Add(4, 4)
' Create a new art layer containing text
Set artLayerRef = docRef.ArtLayers.Add
artLayerRef.Kind = 2
' Set the contents of the text layer.
Set textItemRef = artLayerRef.TextItem
textItemRef.Contents = "Hello, World!"
' Restore unit setting
appRef.Preferences.RulerUnits = originalRulerUnits
To run this script create a text file and copy the script into it. Save the file with a “vbs”
extension. Double-click the file to execute.