
C
HAPTER
6: Scripting with VBScript
Creating paths and shapes
53
Combining path-point types
The following script sample creates a path with three points:
Set appRef = CreateObject("Illustrator.Application")
Set myDoc = appRef.ActiveDocument
Set myLine = myDoc.PathItems.Add
myLine.Stroked = True
myLine.SetEntirePath( Array( Array(320, 475), Array(375, 300)))
' Append another point to the line
Set newPoint = myLine.PathPoints.Add
'Using identical coordinates creates a straight segment
newPoint.Anchor = Array(220, 300)
newPoint.LeftDirection = Array(220, 300)
newPoint.RightDirection = Array(220, 300)
Shapes
To create a shape, use the
PathItems
method that corresponds to the shape’s name (like
ellipse
,
rectangle
, or
polygon
), and use parameters to specify the shape’s position, size, and other characteristics
like the number of sides in a polygon.
Remember:
➤
The scripting engine processes all measurements and page coordinates as points. For details, see
“Measurement units” on page 29
.
➤
x and y coordinates are measured from the bottom-left corner of the document, as indicated in the
Info panel in the Illustrator application. For details, see
“Page-item positioning and dimensions” on
page 29
.
Creating a rectangle
Consider the following sample:
Set appRef = CreateObject("Illustrator.Application")
Set frontDocument = appRef.ActiveDocument
' Create a new rectangle with
' top = 144, left side = 144, width = 72, height = 144
Set newRectangle = frontDocument.PathItems.Rectangle(144,144,72,144)
The sample creates a rectangle with these properties:
➤
The top of the rectangle is 2 inches (144 points) from the bottom edge of the page.
➤
The left edge is 2 inches (144 points) from the left edge of the page.
➤
The rectangle is 1 inch (72 points) wide and 2 inches (144 points) long.