Adobe 23101764 Scripting Guide - Page 12

Scripting basics

Page 12 highlights

2 Scripting basics 2.1 Documents as objects If you use Photoshop, then you create documents, layers, channels and design elements and probably think of a Photoshop document as a series of layers and channels - or objects. Automating Photoshop with scripting requires the same object-oriented type of thinking. The heart of a scriptable application is the object model. In Photoshop, the object model is comprised of documents, layers and channels. Each object has its own special properties, and every object in a Photoshop document has its own identity. This chapter covers the basic concepts of scripting within this object-oriented environment. 2.2 Object model concepts The terminology of object-oriented programming can initially be a formidable obstacle to understanding. "Objects" belong to "classes" and have "properties" you manipulate using "commands" (AppleScript) or "methods" (Visual Basic and JavaScript). What do these words mean in this context? It makes sense to think about objects and their properties as components of an object model. Imagine that you live in a house that responds to your commands. The house is an object, and its properties might include the number of rooms, the color of the exterior paint or the date of its construction. Your house can also contain other objects within. Each room, for example, is an object in the house, while each window, door, or appliance is an object inside of the room. And each object can respond to various commands according to its capabilities. Now apply this object model concept to Photoshop. The Photoshop application is the house, its documents are the rooms, and the objects in your documents are the windows and doors. You can tell Photoshop documents to add and remove objects or manipulate individual properties like color, size and shape. Actions can also be performed -- windows and doors, for example, may open and close. 2.2.1 Object classes Objects with the same properties and behaviors are grouped into "classes." In the house example, windows and doors belong to their own classes because they have unique properties. In Photoshop, every type of object- document, art layer, etc.-belongs to its own class, each with its own set of properties and behaviors. Photoshop CS Scripting Guide 8

  • 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
8
2
Scripting basics
2.1 Documents as objects
If you use Photoshop, then you create documents, layers, channels and design elements and
probably think of a Photoshop document as a series of layers and channels — or objects.
Automating Photoshop with scripting requires the same object-oriented type of thinking.
The heart of a scriptable application is the object model. In Photoshop, the object model is
comprised of documents, layers and channels. Each object has its own special properties, and
every object in a Photoshop document has its own identity.
This chapter covers the basic concepts of scripting within this object-oriented environment.
2.2 Object model concepts
The terminology of object-oriented programming can initially be a formidable obstacle to
understanding. “Objects” belong to “classes” and have “properties” you manipulate using
“commands” (AppleScript) or “methods” (Visual Basic and JavaScript). What do these words
mean in this context?
It makes sense to think about objects and their properties as components of an object model.
Imagine that you live in a house that responds to your commands. The house is an object, and
its properties might include the number of rooms, the color of the exterior paint or the date of
its construction.
Your house can also contain other objects within. Each room, for example, is an object in the
house, while each window, door, or appliance is an object inside of the room. And each object
can respond to various commands according to its capabilities.
Now apply this object model concept to Photoshop. The Photoshop application is the house,
its documents are the rooms, and the objects in your documents are the windows and doors.
You can tell Photoshop documents to add and remove objects or manipulate individual
properties like color, size and shape. Actions can also be performed -- windows and doors, for
example, may open and close.
2.2.1
Object classes
Objects with the same properties and behaviors are grouped into “classes.” In the house
example, windows and doors belong to their own classes because they have unique properties.
In Photoshop, every type of object— document, art layer, etc.—belongs to its own class, each
with its own set of properties and behaviors.