Adobe 65014912 Scripting Guide - Page 50

Set myPathItem = docRef.PathItems.AddA Line, lineSubPathArray, Set docRef = appRef.Documents.Add5000

Page 50 highlights

CHAPTER 3: Scripting Photoshop Working with the Photoshop Object Model 50 VBS Dim appRef, docRef Dim lineArray(1), lineArray2(1), lineSubPathArray(0), myPathItem Set appRef = CreateObject("Photoshop.Application") ' create a document to work with Set docRef = appRef.Documents.Add(5000, 7000, 72, "Simple Line") 'line #1--it's a straight line so the coordinates for anchor, left, and 'right for each point have the same coordinates 'First create the array of PathPointInfo objects. The line has two points, 'so there are two PathPointInfo objects. Set lineArray(0) = CreateObject("Photoshop.PathPointInfo") lineArray(0).Kind = 2 ' for PsPointKind --> 2 (psCornerPoint) lineArray(0).Anchor = Array(100, 100) lineArray(0).LeftDirection = lineArray(0).Anchor lineArray(0).RightDirection = lineArray(0).Anchor Set lineArray(1) = CreateObject("Photoshop.PathPointInfo") lineArray(1).Kind = 2 lineArray(1).Anchor = Array(150, 200) lineArray(1).LeftDirection = lineArray(1).Anchor lineArray(1).RightDirection = lineArray(1).Anchor 'Next create a SubPathInfo object, which will hold the line array 'in its EntireSubPath property. Set lineSubPathArray(0) = CreateObject("Photoshop.SubPathInfo") lineSubPathArray(0).Operation = 2 'for PsShapeOperation --> 2 (psShapeXOR) lineSubPathArray(0).Closed = false lineSubPathArray(0).EntireSubPath = lineArray 'create the PathItem object using Add. This method takes the SubPathInfo object 'and returns a PathItem object, which is added to the pathItems collection 'for the document. Set myPathItem = docRef.PathItems.Add("A Line", lineSubPathArray) ' stroke it so we can see something myPathItem.StrokePath(2) 'for PsToolType --> 2 (psBrush) JS // create a document to work with var docRef = app.documents.add(5000, 7000, 72, "Simple Line") //line #1--it's a straight line so the coordinates for anchor, left, and //right //for each point have the same coordinates // First create the array of PathPointInfo objects. The line has two points, // so there are two PathPointInfo objects. var lineArray = new Array() lineArray[0] = new PathPointInfo lineArray[0].kind = PointKind.CORNERPOINT lineArray[0].anchor = Array(100, 100) lineArray[0].leftDirection = lineArray[0].anchor lineArray[0].rightDirection = lineArray[0].anchor lineArray[1] = new PathPointInfo lineArray[1].kind = PointKind.CORNERPOINT lineArray[1].anchor = Array(150, 200) lineArray[1].leftDirection = lineArray[1].anchor lineArray[1].rightDirection = lineArray[1].anchor

  • 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
50
VBS
Dim appRef, docRef
Dim lineArray(1), lineArray2(1), lineSubPathArray(0), myPathItem
Set appRef = CreateObject("Photoshop.Application")
' create a document to work with
Set docRef = appRef.Documents.Add(5000, 7000, 72, "Simple Line")
'line #1--it’s a straight line so the coordinates for anchor, left, and
'right for each point have the same coordinates
'First create the array of PathPointInfo objects. The line has two points,
'so there are two PathPointInfo objects.
Set lineArray(0) = CreateObject("Photoshop.PathPointInfo")
lineArray(0).Kind = 2 ' for PsPointKind --> 2 (psCornerPoint)
lineArray(0).Anchor = Array(100, 100)
lineArray(0).LeftDirection = lineArray(0).Anchor
lineArray(0).RightDirection = lineArray(0).Anchor
Set lineArray(1) = CreateObject("Photoshop.PathPointInfo")
lineArray(1).Kind = 2
lineArray(1).Anchor = Array(150, 200)
lineArray(1).LeftDirection = lineArray(1).Anchor
lineArray(1).RightDirection = lineArray(1).Anchor
'Next create a SubPathInfo object, which will hold the line array
'in its EntireSubPath property.
Set lineSubPathArray(0) = CreateObject("Photoshop.SubPathInfo")
lineSubPathArray(0).Operation = 2 'for PsShapeOperation --> 2 (psShapeXOR)
lineSubPathArray(0).Closed = false
lineSubPathArray(0).EntireSubPath = lineArray
'create the PathItem object using Add. This method takes the SubPathInfo object
'and returns a PathItem object, which is added to the pathItems collection
'for the document.
Set myPathItem = docRef.PathItems.Add("A Line", lineSubPathArray)
' stroke it so we can see something
myPathItem.StrokePath(2) 'for PsToolType --> 2 (psBrush)
JS
// create a document to work with
var docRef = app.documents.add(5000, 7000, 72, "Simple Line")
//line #1--it’s a straight line so the coordinates for anchor, left, and //right
//for each point have the same coordinates
// First create the array of PathPointInfo objects. The line has two points,
// so there are two PathPointInfo objects.
var lineArray = new Array()
lineArray[0] = new PathPointInfo
lineArray[0].kind = PointKind.CORNERPOINT
lineArray[0].anchor = Array(100, 100)
lineArray[0].leftDirection = lineArray[0].anchor
lineArray[0].rightDirection = lineArray[0].anchor
lineArray[1] = new PathPointInfo
lineArray[1].kind = PointKind.CORNERPOINT
lineArray[1].anchor = Array(150, 200)
lineArray[1].leftDirection = lineArray[1].anchor
lineArray[1].rightDirection = lineArray[1].anchor