Adobe 65010248 Scripting Guide - Page 52

Specifying a series of x-y coordinates, Using path point objects, object have the same coordinates

Page 52 highlights

CHAPTER 6: Scripting with VBScript Creating paths and shapes 52 Using x-y coordinates limits the path to straight segments. To created a curved path, you must create PathPoint objects. Your path can comprise a combination of page coordinates and PathPoint objects. Specifying a series of x-y coordinates To specify a path using page-coordinate pairs, use the SetEntirePath() method of the PathItems object. The following script specifies three pairs of x-y coordinates, to create a path with three points: Set appRef = CreateObject ("Illustrator.Application") Set firstPath = appRef.ActiveDocument.PathItems.Add firstPath.Stroked = True firstPath.SetEntirePath(Array(Array(220, 475),Array(375, 300),Array(200, 300))) Using path point objects To create a PathPoint object, you must define three values for the point: ➤ A fixed anchor point, which is the point on the path. ➤ A pair of direction points-left direction and right direction-which allow you to control the path segment's curve. You define each property as an array of page coordinates in the format (Array (x,y)). ➤ If all three properties of a PathPoint object have the same coordinates, and the properties of the next PathPoint in the line are equal to each other, you create a straight-line segment. ➤ If two or more properties in a PathPoint object hold different values, the segment connected to the point is curved. To create a path or add points to an existing path using PathPoint objects, create a PathItem object, then add the path points as child objects in the PathItem: Set appRef = CreateObject ("Illustrator.Application") Set firstPath = appRef.ActiveDocument.PathItems.Add firstPath.Stroked = true Set newPoint = firstPath.PathPoints.Add 'Using identical coordinates creates a straight segment newPoint.Anchor = Array(75, 300) newPoint.LeftDirection = Array(75, 300) newPoint.RightDirection = Array(75, 300) Set newPoint2 = firstPath.PathPoints.Add newPoint2.Anchor = Array(175, 250) newPoint2.LeftDirection = Array(175, 250) newPoint2.RightDirection = Array(175, 250) Set newPoint3 = firstPath.PathPoints.Add 'Using different coordinates creates a curve newPoint3.Anchor = Array(275, 290) newPoint3.LeftDirection = Array(135, 150) newPoint3.RightDirection = Array(155, 150)

  • 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

C
HAPTER
6: Scripting with VBScript
Creating paths and shapes
52
Using x-y coordinates limits the path to straight segments. To created a curved path, you must create
PathPoint
objects. Your path can comprise a combination of page coordinates and
PathPoint
objects.
Specifying a series of x-y coordinates
To specify a path using page-coordinate pairs, use the
SetEntirePath()
method of the
PathItems
object. The following script specifies three pairs of x-y coordinates, to create a path with three points:
Set appRef = CreateObject ("Illustrator.Application")
Set firstPath = appRef.ActiveDocument.PathItems.Add
firstPath.Stroked = True
firstPath.SetEntirePath(Array(Array(220, 475),Array(375, 300),Array(200, 300)))
Using path point objects
To create a
PathPoint
object, you must define three values for the point:
A fixed
anchor
point, which is the point on the path.
A pair of direction points—
left
direction
and
right
direction
—which allow you to control the
path segment’s curve.
You define each property as an array of page coordinates in the format
(Array
(x,y))
.
If all three properties of a
PathPoint
object have the same coordinates, and the properties of the next
PathPoint
in the line are equal to each other, you create a straight-line segment.
If two or more properties in a
PathPoint
object hold different values, the segment connected to the
point is curved.
To create a path or add points to an existing path using
PathPoint
objects, create a
PathItem
object, then
add the path points as child objects in the
PathItem
:
Set appRef = CreateObject ("Illustrator.Application")
Set firstPath = appRef.ActiveDocument.PathItems.Add
firstPath.Stroked = true
Set newPoint = firstPath.PathPoints.Add
'Using identical coordinates creates a straight segment
newPoint.Anchor = Array(75, 300)
newPoint.LeftDirection = Array(75, 300)
newPoint.RightDirection = Array(75, 300)
Set newPoint2 = firstPath.PathPoints.Add
newPoint2.Anchor = Array(175, 250)
newPoint2.LeftDirection = Array(175, 250)
newPoint2.RightDirection = Array(175, 250)
Set newPoint3 = firstPath.PathPoints.Add
'Using different coordinates creates a curve
newPoint3.Anchor = Array(275, 290)
newPoint3.LeftDirection = Array(135, 150)
newPoint3.RightDirection = Array(155, 150)