
C
HAPTER
5: Scripting with JavaScript
Creating paths and shapes
47
Creating a rectangle
Consider the following sample
var myDocument = app.documents.add()
var artLayer = myDocument.layers.add()
var rect = artLayer.pathItems.rectangle( 144, 144, 72, 216 );
The sample uses the
pathItems
object’s
rectangle()
method to create 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 3 inches (216 points) long.
Creating a polygon
Consider the following sample:
var myDocument = app.documents.add()
var artLayer = myDocument.layers.add()
var poly = artLayer.pathItems.polygon( 144, 288, 72.0, 7 );
The sample uses the
polygon()
method to create a polygon with these properties:
➤
The center point of the object is inset is 2 inches (144 points) on the horizontal axis and 4 inches (288
points) on the vertical axis.
➤
The length of the radius from the center point to each corner is 1 inch (72 points).
➤
The polygon has 7 sides.