Adobe 23102480 Scripting Guide - Page 34

Working with Layer Objects, Creating an ArtLayer Object, Photoshop CS3 application.

Page 34 highlights

Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Scripting Photoshop CS3 34 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 CS3 object model contains two types of layer objects: ● ArtLayer objects, which can contain image contents and are basically equivalent to Layers in the Photoshop CS3 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. Creating an ArtLayer Object The following examples demonstrate how to create an ArtLayer object filled with red at the beginning of the current document. AS tell application "Adobe Photoshop CS3" make new document make new art layer at beginning of current document ¬ with properties {name:"MyBlendLayer", blend mode:normal} select all current document fill selection of current document with contents ¬ {class:RGB color, red:255, green:0, blue:0} end tell

  • 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

Photoshop CS3
Adobe Photoshop CS3
Scripting Guide
Scripting Photoshop CS3
34
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 CS3 object model contains two types of layer objects:
ArtLayer
objects, which can contain image contents and are basically equivalent to Layers in the
Photoshop CS3 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.
Creating an ArtLayer Object
The following examples demonstrate how to create an
ArtLayer
object filled with red at the beginning of
the current document.
AS
tell application "Adobe Photoshop CS3"
make new document
make new art layer at beginning of current document ¬
with properties {name:"MyBlendLayer", blend mode:normal}
select all current document
fill selection of current document with contents ¬
{class:RGB color, red:255, green:0, blue:0}
end tell