Adobe 16001500 Getting Started Guide - Page 5
Example 4: Creating New Objects
UPC - 718659425425
View all Adobe 16001500 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 5 highlights
GettingStarted Illustrator JavaScript 5 8. Each element in the collection is an object of the desired type, and you can access its properties. To get an object's name, for example, use the name property: var styleName = lastStyle.name; 9. To apply lastStyle to the first pageItem in the document, use its applyTo method: lastStyle.applyTo( app.activeDocument.pageItems[0] ); 10. To reference the first pathItem in the active document use the pathItems collection: pathRef = app.activeDocument.pathItems[0]; 11. A pathItem is made up of path points. Hence to access the points in the pathRef object: pathRefPoints = pathRef.pathPoints; a. To get the type of the point use the pointType property: alert ( pathRefPoints[0].pointType ); 12. Save the file. 13. Run the script, as described in Executing JavaScript Scripts above. The alert boxes appear with total number of brushes and the pathItem's PointType and and lastStyle is applied to the first pageItem in the document. You can use this technique to access raster items, groups, items within a group, gradients, colors, textFrames, and other object types in a document and manipulate them needed. Example 4: Creating New Objects You can use a script to create new documents, and new objects, rather than accessing any existing documents or objects. This script does not have to check whether a document is open and objects are present, because it creates a new blank document and creates some objects in it. This simple example creates some basic shapes in the first layer of the frontmost document and applies a random graphic style to it. Each shape is defined by new pathItem objects. 1. Open a new blank document in your text editor, and save it as Example3.js. 2. Create a new blank Illustrator document. // open a new blank document var thisDoc = app.documents.add(); 3. Create a new layer. // add a new layer var artLayer = thisDoc.layers.add(); 4. Set the default stroke and fill settings for all the objects using the app object (the Illustrator Application object that contains all other Illustrator objects). // default stroke and fill settings app.defaultStroked = true; app.defaultFilled = true;