Adobe 23101764 Scripting Guide - Page 13

Object inheritance, Object elements or collections, Object reference

Page 13 highlights

Scripting basics 2 Object model concepts 2.2.2 Object inheritance Object classes may also "inherit," or share, the properties of a parent, or superclass. When a class inherits properties, we call that class a child, or subclass of the class from which it inherits properties. So in our house example, windows and doors are subclasses of an openings class, since they are both openings in a house. In Photoshop, art layers, for example, inherit from the layer class. Classes often have properties that aren't shared with their superclass. Both a window and a door, for example, inherit an "opened" property from the opening class, but a window has a "number of panes" property which the Opening class does not. In Photoshop, art layers, for example, have the property "grouped" which is not inherited from the Layer class. 2.2.3 Object elements or collections Object elements (AppleScript) or collections (Visual Basic, JavaScript) are objects contained within other objects. For example, rooms are elements (or collections) of our house, contained within the house object. In Photoshop, documents are elements of the application object, and layers are elements of a document object. To access an element (or member of a collection), you use an index. For example, to get the first document of the application you write: AS: document 1 VB: appRef.Documents (1) JS: app.documents[0]; IMPORTANT: Indices in AppleScript and Visual Basic are 1 based. JavaScript indices are 0 based. 2.2.4 Object reference The objects in Photoshop documents are arranged in a hierarchy like the house object - layers are contained within layer sets, which are placed inside a document which exists within the Photoshop application. When you send a command to a Photoshop object, you need to make sure you send the message to the right object. To do this, you identify objects by their position in the hierarchy - by an object reference. You might, for example, write the following statement. AppleScript layer 1 of layer set 1 of current document Visual Basic appRef.ActiveDocument.LayerSets(1).Layers(1) Photoshop CS Scripting Guide 9

  • 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
9
Scripting basics
Object model concepts
2
2.2.2
Object inheritance
Object classes may also “inherit,” or share, the properties of a parent, or superclass. When a
class inherits properties, we call that class a child, or subclass of the class from which it
inherits properties. So in our house example, windows and doors are subclasses of an openings
class, since they are both openings in a house. In Photoshop, art layers, for example, inherit
from the layer class.
Classes often have properties that aren’t shared with their superclass. Both a window and a
door, for example, inherit an "opened" property from the opening class, but a window has a
"number of panes" property which the Opening class does not. In Photoshop, art layers, for
example, have the property "grouped" which is not inherited from the Layer class.
2.2.3
Object elements or collections
Object elements (AppleScript) or collections (Visual Basic, JavaScript) are objects contained
within other objects. For example, rooms are elements (or collections) of our house, contained
within the house object. In Photoshop, documents are elements of the application object, and
layers are elements of a document object. To access an element (or member of a collection),
you use an index. For example, to get the
rst document of the application you write:
AS:
document 1
VB:
appRef.Documents (1)
JS: app.
documents[0];
IMPORTANT:
Indices in AppleScript and Visual Basic are 1 based. JavaScript indices are 0
based.
2.2.4
Object reference
The objects in Photoshop documents are arranged in a hierarchy like the house object —
layers are contained within layer sets, which are placed inside a document which exists within
the Photoshop application. When you send a command to a Photoshop object, you need to
make sure you send the message to the right object. To do this, you identify objects by their
position in the hierarchy — by an object reference. You might, for example, write the
following statement.
AppleScript
layer 1 of layer set 1 of current document
Visual Basic
appRef.ActiveDocument.LayerSets(1).Layers(1)