Adobe 65014293 Scripting Guide - Page 42

Adding and manipulating text in a Text Item object, Working with Selection objects

Page 42 highlights

CHAPTER 3: Scripting Photoshop Working with the Photoshop Object Model 42 Adding and manipulating text in a Text Item object AS VBS The following examples add and right-justify text in a text layer. set layerRef to make new art layer in current document with properties¬ {kind:text layer} set contents of text object of layerRef to "Hello, World!" set justification of text object of layerRef to right Set textLayerRef = docRef.ArtLayers.Add() textLayerRef.Kind = 2 textLayerRef.Name = "my text" Set textItemRef = docRef.ArtLayers("my text").TextItem textItemRef.Contents = "Hello, World!" textItemRef.Justification = 3 '3 = psRight (for the constant value psJustification) JS var textLayerRef = docRef.artLayers.add() textLayerRef.name = "my text" textLayerRef.kind = LayerKind.TEXT var textItemRef = docRef.artLayers["my text"].textItem textItemRef.contents = "Hello, World!" textItemRef.justification = Justification.RIGHT NOTE: The text-object (TextItem/TextItem) object has a kind Kind/kind) property, which can be set to either point text (psPointText/TextType.POINTTEXT) or paragraph text (psParagraphText/TextType.PARAGRAPHTEXT.) When a new text-object is created, its kind property is automatically set to point text. The text-object properties height, width, and leading are valid only when the text item's kind property is set to paragraph text. To familiarize yourself with this objects, properties, and commands in the scripting references, do the following: ➤ In the Adobe Photoshop CS4 AppleScript Scripting Reference or in the Photoshop AppleScript Dictionary, look up the text-object properties and methods. ➤ In the Adobe Photoshop CS4 Visual Basic Scripting Reference, or in the Visual Basic Object Browser look up the TextItem property of the ArtLayer object. To find the properties and methods you can use with a text layer, look up the TextItem object. In the Adobe Photoshop CS4 JavaScript Scripting Reference, or in the ExtendScript Object Model Viewer, look up the textItem property of the ArtLayer object. To find the properties and methods you can use with a text layer, look up the TextItem object. Working with Selection objects You use a Selection object to allow your scripts to act only on a specific, selected section of your document or a layer within a document. For example, you can apply effects to a selection or copy the current selection to the clipboard.

  • 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
42
Adding and manipulating text in a Text Item object
The following examples add and right-justify text in a text layer.
AS
set layerRef to make new art layer in current document with properties¬
{kind:text layer}
set contents of text object of layerRef to "Hello, World!"
set justification of text object of layerRef to right
VBS
Set textLayerRef = docRef.ArtLayers.Add()
textLayerRef.Kind = 2
textLayerRef.Name = "my text"
Set textItemRef = docRef.ArtLayers("my text").TextItem
textItemRef.Contents = "Hello, World!"
textItemRef.Justification = 3
'3 = psRight (for the constant value psJustification)
JS
var textLayerRef = docRef.artLayers.add()
textLayerRef.name = "my text"
textLayerRef.kind = LayerKind.TEXT
var textItemRef = docRef.artLayers["my text"].textItem
textItemRef.contents = "Hello, World!"
textItemRef.justification = Justification.RIGHT
N
OTE
:
The
text-object
(
TextItem/TextItem
) object has a
kind
Kind/kind)
property, which can be set
to either
point
text
(psPointText/TextType.POINTTEXT
) or
paragraph
text
(psParagraphText/TextType.PARAGRAPHTEXT
.) When a new
text-object
is created, its
kind
property
is automatically set to
point
text
.
The
text-object
properties
height
,
width
, and
leading
are valid only when the text item's
kind
property is set to
paragraph text
.
To familiarize yourself with this objects, properties, and commands in the scripting references, do the
following:
In the
Adobe Photoshop CS4 AppleScript Scripting Reference
or in the Photoshop AppleScript Dictionary,
look up the
text-object
properties and methods.
In the
Adobe Photoshop CS4 Visual Basic Scripting Reference
, or in the Visual Basic Object Browser look
up the
TextItem
property of the
ArtLayer
object. To find the properties and methods you can use
with a text layer, look up the
TextItem
object.
In the
Adobe Photoshop CS4 JavaScript Scripting Reference
, or in the ExtendScript Object Model Viewer, look
up the
textItem
property of the
ArtLayer
object. To find the properties and methods you can use with a
text layer, look up the
TextItem
object.
Working with Selection objects
You use a
Selection
object to allow your scripts to act only on a specific, selected section of your
document or a layer within a document. For example, you can apply effects to a selection or copy the
current selection to the clipboard.