Adobe 65015634 Scripting Guide - Page 35

Manipulating a document object, Setting Application Preferences

Page 35 highlights

CHAPTER 3: Scripting Photoshop Working with the Photoshop Object Model 35 Manipulating a document object The following examples demonstrate how to do the following: ➤ Save the existing ruler unit preferences, and set ruler units to inches ➤ Open an existing file as a document (using file Ducky.tif) ➤ Change the size of the image to 4 inches wide and 4 inches high. ➤ Change the size of the document window (or canvas) to 4 inches high and 4 inches wide. ➤ Trim the top and bottom of the image. ➤ Crop the image. ➤ Flip the entire window. ➤ Restore the original ruler units. NOTE: See "Setting Application Preferences" on page 32 for information on ruler units. AS tell application "Adobe Photoshop CS4" set saveUnit to ruler units of settings set ruler units of settings to inch units set duckFile to alias ¬ "OS X 10.4.8 US:Applications:Adobe Photoshop CS4:Samples:Ducky.tif" open duckFile set docRef to current document resize image docRef width 4 height 4 resize canvas docRef width 4 height 4 trim docRef basing trim on top left pixel with top trim ¬ and bottom trim without left trim and right trim set ruler units of settings to pixel units crop current document bounds {100, 200, 400, 500} angle 45 width 20 height 20 flip canvas docRef direction horizontal set ruler units of settings to saveUnit end tell VBS Dim appRef, docRef Set appRef = CreateObject("Photoshop.Application") 'save original ruler units, then set ruler units to inches startRulerUnits = appRef.Preferences.RulerUnits appRef.Preferences.RulerUnits = 2 'for PsUnits --> 2 (psInches) Set docRef = appRef.Open(appRef.Path & "\Samples\Ducky.tif") docRef.ResizeImage 4,4 docRef.ResizeCanvas 4,4 'Trim the document with ' type = 1 (psTopLeftPixel) ' top=true, left=false, bottom=true, right=false docRef.Trim 1,True,False,True,False 'the crop command uses unit values 'so change the ruler units to pixels appRef.Preferences.RulerUnits = 1 ' (psPixels)

  • 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
Working with the Photoshop Object Model
35
Manipulating a document object
The following examples demonstrate how to do the following:
Save the existing ruler unit preferences, and set ruler units to inches
Open an existing file as a document (using file Ducky.tif )
Change the size of the image to 4 inches wide and 4 inches high.
Change the size of the document window (or canvas) to 4 inches high and 4 inches wide.
Trim the top and bottom of the image.
Crop the image.
Flip the entire window.
Restore the original ruler units.
N
OTE
:
See
“Setting Application Preferences” on page 32
for information on ruler units.
AS
tell application "Adobe Photoshop CS4"
set saveUnit to ruler units of settings
set ruler units of settings to inch units
set duckFile to alias ¬
"OS X 10.4.8 US:Applications:Adobe Photoshop CS4:Samples:Ducky.tif"
open duckFile
set docRef to current document
resize image docRef width 4 height 4
resize canvas docRef width 4 height 4
trim docRef basing trim on top left pixel with top trim ¬
and bottom trim without left trim and right trim
set ruler units of settings to pixel units
crop current document bounds {100, 200, 400, 500} angle 45 width 20 height 20
flip canvas docRef direction horizontal
set ruler units of settings to saveUnit
end tell
VBS
Dim appRef, docRef
Set appRef = CreateObject("Photoshop.Application")
'save original ruler units, then set ruler units to inches
startRulerUnits = appRef.Preferences.RulerUnits
appRef.Preferences.RulerUnits = 2 'for PsUnits --> 2 (psInches)
Set docRef = appRef.Open(appRef.Path & "\Samples\Ducky.tif")
docRef.ResizeImage 4,4
docRef.ResizeCanvas 4,4
'Trim the document with
'
type = 1 (psTopLeftPixel)
'
top=true, left=false, bottom=true, right=false
docRef.Trim 1,True,False,True,False
'the crop command uses unit values
'so change the ruler units to pixels
appRef.Preferences.RulerUnits = 1 ' (psPixels)