Adobe 65010248 Scripting Guide - Page 53

Combining path-point types, Shapes, Creating a rectangle

Page 53 highlights

CHAPTER 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.

  • 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
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.