C
HAPTER
3: Scripting Photoshop
Working with the Photoshop Object Model
41
Using the Text Item object
You can change an existing
ArtLayer
object to a text layer, that is, a
Text
Item
object, if the layer is
empty. Conversely you can change a
Text
Item
object to an
ArtLayer
object. This “reverse” procedure
rasterizes the text in the layer object.
The
Text
Item
object is a property of the
ArtLayer
object. However, to create a new text layer, you must
create a new
ArtLayer
object and then set the art layer's
kind/Kind/kind
property to
text
layer
(2
(psTextLayer)/
LayerKind.TEXT
).
To set or manipulate text in a text layer, you use the
text-object
(TextItem/TextItem)
object, which is
contained in the
text
object/TextItem/textItem
property of the
ArtLayer
object.
Creating a Text Item object
The following examples create an
ArtLayer
object and then use the
kind
property to convert it to a text
layer.
AS
make new art layer in current document with properties { kind: text layer }
VBS
set newLayerRef = docRef.ArtLayers.Add()
newLayerRef.Kind = 2
'2 indicates psTextLayer
JS
var newLayerRef = docRef.artLayers.add()
newLayerRef.kind = LayerKind.TEXT
See
“Photoshop Object Model” on page 11
for information on the relationship between
ArtLayer
objects
and
TextItem
objects.
Also, look up the following:
➤
The
Kind/kind
and
TextItem/textItem
properties of the
ArtLayer
object in the
Adobe Photoshop
CS4 Visual Basic Scripting Reference
,
Adobe Photoshop CS4 JavaScript Scripting Reference
, or in the Visual
Basic Object Browser and the ExtendScript Object Model Viewer.
➤
The
kind
and
text
object
properties of the class
art
layer
in the
Adobe Photoshop CS4 AppleScript
Scripting Reference
or in the Photoshop AppleScript Dictionary.
Determining a layer’s kind
The following examples use an
if
statement to check whether an existing layer is a text layer.
AS
if (kind of layerRef is text layer) then
...
endif
VBS
If layerRef.Kind = 2 Then '2 indicates psTextLayer
...
End If
JS
if (newLayerRef.kind == LayerKind.TEXT)
{...}