Adobe 65015634 Scripting Guide - Page 62

Photoshop > Preferences > Units & Rulers, In Photoshop, choose

Page 62 highlights

CHAPTER 3: Scripting Photoshop Advanced Scripting 62 VBS --check to see whether any documents are open --if none are found, create a document --use the default document settings as its properties if (count of documents) is 0 then make new document with properties ¬ {width:theDocWidthInInches, height:theDocHeightInInches,¬ resolution:theDocResolution, name:theDocString} end if --change the settings back to the original units stored in the variables set ruler units of settings to theStartRulerUnits set type units of settings to theStartTypeUnits set display dialogs to theStartDisplayDialogs end tell 2. In Photoshop, choose Photoshop > Preferences > Units & Rulers to verify that your preferences have been returned to your original settings. 3. After viewing the document in Photoshop, close the document without saving it. 4. Save the script as HelloWorldDoc. To work with document preferences: 1. Create the following script. See "Creating and running a VBScript" on page 19 for details. 'create variables for default preferences, new preferences Dim startRulerUnits Dim startTypeUnits Dim docWidthInInches Dim docHeightInInches Dim resolution Dim helloWorldStr Dim appRef Set appRef = CreateObject("Photoshop.Application") 'assign default preferences to save values in variables startRulerUnits = appRef.Preferences.RulerUnits startTypeUnits = appRef.Preferences.TypeUnits startDisplayDialogs = appRef.DisplayDialogs 'set new preferences and document defaults appRef.Preferences.RulerUnits = 2 'for PsUnits --> 2 (psInches) appRef.Preferences.TypeUnits = 1 'for PsTypeUnits --> 1 (psPixels) appRef.DisplayDialogs = 3 'for PsDialogModes --> 3 (psDisplayNoDialogs) docWidthInInches = 4 docHeightInInches = 2 resolution = 72 helloWorldStr = "Hello, World!" 'see if any documents are open 'if none, create one using document defaults If appRef.Documents.Count = 0 Then appRef.Documents.Add docWidthInInches, docHeightInInches, resolution, helloWorldStr End If

  • 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
Advanced Scripting
62
--check to see whether any documents are open
--if none are found, create a document
--use the default document settings as its properties
if (count of documents) is 0 then
make new document with properties ¬
{width:theDocWidthInInches, height:theDocHeightInInches,¬
resolution:theDocResolution, name:theDocString}
end if
--change the settings back to the original units stored in the variables
set ruler units of settings to theStartRulerUnits
set type units of settings to theStartTypeUnits
set display dialogs to theStartDisplayDialogs
end tell
2.
In Photoshop, choose
Photoshop > Preferences > Units & Rulers
to verify that your preferences
have been returned to your original settings.
3.
After viewing the document in Photoshop, close the document without saving it.
4.
Save the script as
HelloWorldDoc
.
VBS
To work with document preferences:
1.
Create the following script. See
“Creating and running a VBScript” on page 19
for details.
'create variables for default preferences, new preferences
Dim startRulerUnits
Dim startTypeUnits
Dim docWidthInInches
Dim docHeightInInches
Dim resolution
Dim helloWorldStr
Dim appRef
Set appRef = CreateObject("Photoshop.Application")
'assign default preferences to save values in variables
startRulerUnits = appRef.Preferences.RulerUnits
startTypeUnits = appRef.Preferences.TypeUnits
startDisplayDialogs = appRef.DisplayDialogs
'set new preferences and document defaults
appRef.Preferences.RulerUnits = 2 'for PsUnits --> 2 (psInches)
appRef.Preferences.TypeUnits = 1 'for PsTypeUnits --> 1 (psPixels)
appRef.DisplayDialogs = 3 'for PsDialogModes --> 3 (psDisplayNoDialogs)
docWidthInInches = 4
docHeightInInches = 2
resolution = 72
helloWorldStr = "Hello, World!"
'see if any documents are open
'if none, create one using document defaults
If appRef.Documents.Count = 0 Then
appRef.Documents.Add docWidthInInches, docHeightInInches, resolution,
helloWorldStr
End If