Adobe 65014293 Scripting Guide - Page 36

Working with layer objects, objects have corresponding collection objects

Page 36 highlights

CHAPTER 3: Scripting Photoshop Working with the Photoshop Object Model 36 'Crop the document with ' angle=45, width=20,height=20 docRef.Crop Array(100,200,400,500),45,20,20 docRef.FlipCanvas 1 ' psHorizontal 'restore ruler units appRef.Preferences.RulerUnits = startRulerUnits JS //save original ruler units, then assign it to inches startRulerUnits = app.preferences.rulerUnits app.preferences.rulerUnits = Units.INCHES //get a reference to the file, and open it var fileRef = new File(app.path + "/samples/ducky.tif") var docRef = app.open(fileRef) //this sample script assumes the ruler units have been set to inches docRef.resizeImage( 4,4 ) docRef.resizeCanvas( 4,4 ) docRef.trim(TrimType.TOPLEFT, true, false, true, false) //the crop command uses unit values //so change the ruler units to pixels app.preferences.rulerUnits =Units.PIXELS docRef.crop (new Array(100,200,400,500), 45, 20, 20) docRef.flipCanvas(Direction.HORIZONTAL) //restore original preferences app.preferences.rulerUnits = startRulerUnits Working with layer objects The Photoshop object model contains two types of layer objects: ➤ ArtLayer objects, which can contain image contents and are basically equivalent to Layers in the Photoshop application. NOTE: An ArtLayer object can also contain text if you use the kind property to set the ArtLayer object's type to text layer. ➤ Layer Set objects, which can contain zero or more ArtLayer objects. When you create a layer you must specify whether you are creating an ArtLayer or a Layer Set. NOTE: Both the ArtLayer and LayerSet objects have corresponding collection objects, ArtLayers and LayerSets, which have an add/Add/add() command.You can reference, but not add, ArtLayer and LayerSet objects using the Layers collection object, because, unlike other collection objects, it does not have an add/Add/add() command.

  • 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
36
'Crop the document with
'
angle=45, width=20,height=20
docRef.Crop Array(100,200,400,500),45,20,20
docRef.FlipCanvas
1 ' psHorizontal
'restore ruler units
appRef.Preferences.RulerUnits = startRulerUnits
JS
//save original ruler units, then assign it to inches
startRulerUnits = app.preferences.rulerUnits
app.preferences.rulerUnits = Units.INCHES
//get a reference to the file, and open it
var fileRef = new File(app.path + "/samples/ducky.tif")
var docRef = app.open(fileRef)
//this sample script assumes the ruler units have been set to inches
docRef.resizeImage( 4,4 )
docRef.resizeCanvas( 4,4 )
docRef.trim(TrimType.TOPLEFT, true, false, true, false)
//the crop command uses unit values
//so change the ruler units to pixels
app.preferences.rulerUnits =Units.PIXELS
docRef.crop (new Array(100,200,400,500), 45, 20, 20)
docRef.flipCanvas(Direction.HORIZONTAL)
//restore original preferences
app.preferences.rulerUnits = startRulerUnits
Working with layer objects
The Photoshop object model contains two types of layer objects:
ArtLayer
objects, which can contain image contents and are basically equivalent to Layers in the
Photoshop application.
N
OTE
:
An
ArtLayer
object can also contain text if you use the
kind
property to set the
ArtLayer
object’s type to text layer.
Layer Set
objects, which can contain zero or more
ArtLayer
objects.
When you create a layer you must specify whether you are creating an
ArtLayer
or a
Layer Set
.
N
OTE
:
Both the
ArtLayer
and
LayerSet
objects have corresponding collection objects,
ArtLayers
and
LayerSets
, which have an
add/Add/add()
command.You can reference, but not add,
ArtLayer
and
LayerSet
objects using the
Layers
collection object, because, unlike other collection objects, it does not
have an
add/Add/add()
command.