Adobe 23101764 Scripting Guide - Page 47

Displaying Colored Text

Page 47 highlights

Scripting Photoshop 3 Advanced Scripting Displaying Colored Text Having generated a default document, you can now display colored text. To do so, first set a local reference to the current document. Then create a SolidColor object and assign RGB color values to it. After defining the text for the current layer, create an art layer of type TEXT. NOTE: For a complete listing of all JavaScript properties, methods and constants (such as TEXT), please refer to the JavaScript Reference Guide, included as a separate document with Photoshop CS. Next, set the text, position, size and color of the text layer. The content of the text layer is the expression "Hello, World!". Notice that the position property of the text layer is an array whose values were chosen to roughly center the text in the dialog. A relatively large font size was chosen to increase the visibility of the text message. The color property is the SolidColor object created earlier, whose function is to display text in red. docRef = app.activeDocument; textColor = new SolidColor; textColor.rgb.red = 255; textColor.rgb.green = 0; textColor.rgb.blue = 0; helloWorldText = "Hello, World!"; newTextLayer = docRef.artLayers.add(); newTextLayer.kind = LayerKind.TEXT; newTextLayer.textItem.contents = helloWorldText; newTextLayer.textItem.position = Array(0.75, 1); newTextLayer.textItem.size = 36; newTextLayer.textItem.color = textColor; This code snippet outputs "Hello, World!" in red. Photoshop CS Scripting Guide 43

  • 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
43
Scripting Photoshop
Advanced Scripting
3
Displaying Colored Text
Having generated a default document, you can now display colored text. To do so,
rst set a
local reference to the current document. Then create a SolidColor object and assign RGB color
values to it. After de
ning the text for the current layer, create an art layer of type TEXT.
N
OTE
:
For a complete listing of all JavaScript properties, methods and constants (such as
TEXT), please refer to the JavaScript Reference Guide, included as a separate
document with Photoshop CS.
Next, set the text, position, size and color of the text layer. The content of the text layer is the
expression "Hello, World!".
Notice that the position property of the text layer is an array whose values were chosen to
roughly center the text in the dialog. A relatively large font size was chosen to increase the
visibility of the text message. The color property is the SolidColor object created earlier,
whose function is to display text in red.
docRef = app.activeDocument;
textColor = new SolidColor;
textColor.rgb.red = 255;
textColor.rgb.green = 0;
textColor.rgb.blue = 0;
helloWorldText = "Hello, World!";
newTextLayer = docRef.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.textItem.contents = helloWorldText;
newTextLayer.textItem.position = Array(0.75, 1);
newTextLayer.textItem.size = 36;
newTextLayer.textItem.color = textColor;
This code snippet outputs "Hello, World!" in red.