GettingStarted
Illustrator JavaScript 6
5. Create a rectangle using the
rectangle
method of the
pathItems
object. Pass parameters for
position, width, and height of the rectangle. (For details on these parameters see the
pathItems
object in the
JavaScript Reference
.)
// Create different pathItem objects
var rect = artLayer.pathItems.rectangle( 762.5, 87.5, 425.0, 75.0 );
6. Create a rounded rectangle.
var rndRect = artLayer.pathItems.roundedRectangle( 637.5, 87.5, 425.0,
75.0, 20.0, 10.0 );
7. Create an ellipse.
// Create ellipse, 'reversed' == false, 'inscribed' == true
var ellipse = artLayer.pathItems.ellipse( 512.5, 87.5, 425.0,
75.0, false, true );
8. Create an octagon.
// Create octagon, an 8-sided polygon
var octagon = artLayer.pathItems.polygon( 300.0, 325.0, 75.0, 8 );
9. Create a star with four points.
// Create a 4 point star
var star = artLayer.pathItems.star( 300.0, 125.0, 100.0, 20.0, 4 );
10. So far, the objects we have created simply use the default stroke and fill we set in the
app
object. Now
we will access the new objects using the
pathItems
collection, and apply some random graphic
styles to them.
// Apply random graphic style to all the pathItem objects in this document
for ( i = 0; i < artLayer.pathItems.length; i++ )
{
// Obtain a random graphic style number
styleIndex = Math.round( Math.random() * ( thisDoc.graphicStyles.length -
1 ) );
// apply the graphic style at the random index position
thisDoc.graphicStyles[styleIndex].applyTo( artLayer.pathItems[i] );
}
11. Save the file.
12. Run the script, as described in
above.
The objects are created with different graphic styles.
Congratulations! You have now written four JavaScripts for Illustrator. There are more scripts available in
the
Adobe Technical Info > Scripting > Sample Scripts > JavaScript
folder as part of
the Illustrator SDK on the CD.