Adobe 65014293 Scripting Guide - Page 44

Stroking the selection border, Inverting selections, Expanding, contracting, and feathering selections

Page 44 highlights

CHAPTER 3: Scripting Photoshop Working with the Photoshop Object Model 44 JS var docRef = app.documents.add(500, 500) var shapeRef = [ [0,0], [0,100], [100,100], [100,0] ] docRef.selection.select(shapeRef) Stroking the selection border The following examples use the stroke (Stroke/stroke()) command of the Selection object to stroke the boundaries around the current selection and set the stroke color and width. NOTE: The transparency parameter cannot be used for background layers. AS stroke selection of current document using color ¬ {class:CMYK color, cyan:20, magenta:50, yellow:30, black:0} ¬ width 5 location inside blend mode vivid light opacity 75 ¬ without preserving transparency VBS JS Set strokeColor = CreateObject ("Photoshop.SolidColor") strokeColor.CMYK.Cyan = 20 strokeColor.CMYK.Magenta = 50 strokeColor.CMYK.Yellow = 30 strokeColor.CMYK.Black = 0 appRef.ActiveDocument.Selection.Stroke strokeColor, 5, 1, 15, 75, False strokeColor = new solidColor strokeColor.cmyk.cyan = 20 strokeColor.cmyk.magenta = 50 strokeColor.cmyk.yellow = 30 strokeColor.cmyk.black = 0 app.activeDocument.selection.stroke (strokeColor, 2, StrokeLocation.OUTSIDE, ColorBlendMode.VIVIDLIGHT, 75, false) Inverting selections You can use the invert (Invert/invert()) command of the Selection object to a selection so you can work on the rest of the document, layer or channel while protecting the selection. ➤ AS: invert selection of current document ➤ VBS: selRef.Invert ➤ JS: selRef.invert() Expanding, contracting, and feathering selections You can change the size of a selected area using the expand, contract, and feather commands. The values are passed in the ruler units stored in Photoshop preferences and can be changed by your scripts. If your ruler units are set to pixels, then the following examples will expand, contract, and feather

  • 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
44
JS
var docRef = app.documents.add(500, 500)
var shapeRef = [
[0,0],
[0,100],
[100,100],
[100,0]
]
docRef.selection.select(shapeRef)
Stroking the selection border
The following examples use the
stroke
(Stroke/stroke())
command of the
Selection
object to stroke
the boundaries around the current selection and set the stroke color and width.
N
OTE
:
The transparency parameter cannot be used for background layers.
AS
stroke selection of current document using color ¬
{class:CMYK color, cyan:20, magenta:50, yellow:30, black:0} ¬
width 5 location inside blend mode vivid light opacity 75 ¬
without preserving transparency
VBS
Set strokeColor = CreateObject ("Photoshop.SolidColor")
strokeColor.CMYK.Cyan = 20
strokeColor.CMYK.Magenta = 50
strokeColor.CMYK.Yellow = 30
strokeColor.CMYK.Black = 0
appRef.ActiveDocument.Selection.Stroke strokeColor, 5, 1, 15, 75, False
JS
strokeColor = new solidColor
strokeColor.cmyk.cyan = 20
strokeColor.cmyk.magenta = 50
strokeColor.cmyk.yellow = 30
strokeColor.cmyk.black = 0
app.activeDocument.selection.stroke (strokeColor, 2,
StrokeLocation.OUTSIDE, ColorBlendMode.VIVIDLIGHT, 75,
false)
Inverting selections
You can use the
invert (Invert/invert())
command of the
Selection
object to a selection so you
can work on the rest of the document, layer or channel while protecting the selection.
AS:
invert selection of current document
VBS:
selRef.Invert
JS:
selRef.invert()
Expanding, contracting, and feathering selections
You can change the size of a selected area using the expand, contract, and feather commands.
The values are passed in the ruler units stored in Photoshop preferences and can be changed by your
scripts. If your ruler units are set to pixels, then the following examples will expand, contract, and feather