Adobe 23101764 Scripting Guide - Page 50

Advanced Visual Basic

Page 50 highlights

Scripting Photoshop 3 Advanced Scripting 3.4.2 Advanced Visual Basic The following Visual Basic code sample is broken down into four sections, the first of which deals with configuring document preferences. Document Preferences In this code segment, variables are declared and a Photoshop Application object is created. Default configuration settings for the application are saved into variables so that they can be restored later when the script completes. These are the default configurations you most probably set up using the File/Edit/Preferences dialog when you initially installed and configured Photoshop. The script goes on to define new preferences for rulers and units and sets these to inches and pixels, respectively. The psDisplayNoDialogs enumeration is specified so that the script runs without user intervention. Users will not, in other words, be required to press "OK" each time the script generates a new dialog for display. Next, variables are declared that store document dimensions in inches and document resolution in pixels. A display resolution is declared and the text "Hello, World!" is assigned to a string variable. Finally, a document object is created, if one does not already exist. Dim startRulerUnits As Photoshop.PsUnits Dim startTypeUnits As Photoshop.PsTypeUnits Dim startDisplayDialogs As Photoshop.PsDialogModes Dim docWidthInInches As Integer Dim docHeightInInches As Integer Dim docWidthInPixels As Integer Dim docHeightInPixels As Integer Dim resolution As Integer Dim helloWorldStr As String Dim app As Photoshop.Application Dim docRef As Photoshop.Document Dim textColor As Photoshop.SolidColor Dim newTextLayer As Photoshop.ArtLayer Dim Preferences As Photoshop.Preferences Set app = New Photoshop.Application startRulerUnits = app.Preferences.RulerUnits startTypeUnits = app.Preferences.TypeUnits startDisplayDialogs = app.DisplayDialogs Photoshop CS Scripting Guide 46

  • 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
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105

Photoshop CS Scripting Guide
46
Scripting Photoshop
Advanced Scripting
3
3.4.2
Advanced Visual Basic
The following Visual Basic code sample is broken down into four sections, the
rst of which
deals with con
guring document preferences.
Document Preferences
In this code segment, variables are declared and a Photoshop Application object is created.
Default con
guration settings for the application are saved into variables so that they can be
restored later when the script completes. These are the default con
gurations you most
probably set up using the File/Edit/Preferences dialog when you initially installed and
con
gured Photoshop.
The script goes on to de
ne new preferences for rulers and units and sets these to inches and
pixels, respectively. The psDisplayNoDialogs enumeration is speci
ed so that the script runs
without user intervention. Users will not, in other words, be required to press "OK" each time
the script generates a new dialog for display.
Next, variables are declared that store document dimensions in inches and document
resolution in pixels. A display resolution is declared and the text "Hello, World!" is assigned to
a string variable.
Finally, a document object is created, if one does not already exist.
Dim startRulerUnits As Photoshop.PsUnits
Dim startTypeUnits As Photoshop.PsTypeUnits
Dim startDisplayDialogs As Photoshop.PsDialogModes
Dim docWidthInInches As Integer
Dim docHeightInInches As Integer
Dim docWidthInPixels As Integer
Dim docHeightInPixels As Integer
Dim resolution As Integer
Dim helloWorldStr As String
Dim app As Photoshop.Application
Dim docRef As Photoshop.Document
Dim textColor As Photoshop.SolidColor
Dim newTextLayer As Photoshop.ArtLayer
Dim Preferences As Photoshop.Preferences
Set app = New Photoshop.Application
startRulerUnits = app.Preferences.RulerUnits
startTypeUnits = app.Preferences.TypeUnits
startDisplayDialogs = app.DisplayDialogs