Download Print this page
Adobe 16001500 - Illustrator CS2 - Mac Getting Started Manual
Adobe 16001500 - Illustrator CS2 - Mac Getting Started Manual

Adobe 16001500 - Illustrator CS2 - Mac Getting Started Manual

Scripting with javascript
Hide thumbs Also See for 16001500 - Illustrator CS2 - Mac:

Advertisement

Quick Links

Adobe
GettingStarted with JavaScript
Introduction
Scripting offers an easy way to manipulate Illustrator files programmatically. You can write scripts to create
documents and objects, and to perform many of the operations that you access interactively in Illustrator,
using the palettes and windows. Scripts are particularly useful as a way to automate day-to-day tasks that
are complex and repetitive. You simply write the script once, and then run it any time you need to
accomplish that task. This saves you both time and the effort of remembering steps and sequences of
operations.
Illustrator CS2 supports JavaScript, an easy-to-use, platform-independent scripting language. A JavaScript
program, or script, takes the form of a text file with the .js extension. You can use any text editor to write
your scripts, such as TextEdit, Textpad, or BBEdit.
This overview will help you to become familiar with Illustrator scripting using JavaScript, by walking you
through some example scripts that manipulate objects in Illustrator CS2.
This document assumes that:
You are familiar with the Illustrator user interface, as described in the Illustrator CS2 User Guide.
You are familiar with JavaScript programming language.
You have installed Illustrator CS2 version 12.0 and an editor to create scripts, such as Textpad or TextEdit.
Executing JavaScript Scripts
To run any script from Illustrator CS2:
1. Choose File>Scripts>Browse.
2. Navigate to your script file.
3. Double-click the file or click Open to run the script.
To make a script available as a menu item under Illustrator's File>Scripts menu, place the script file in the
directory Adobe Illustrator CS2\Presets\Scripts , then restart Illustrator. Each time you launch
Illustrator, every script found in this location is added as a menu item ,Your script will be listed among the
prebuilt Automation Scripts that are available in this directory.

Accessing and Referencing Objects

When you write a script, you must first decide what file, or document, the script should act on. The script
can create a new document, open an existing document, or act on a document that is already open.
The script can create new objects in the document, operate on objects that the user has selected, or
operate on objects that it finds in one of the object collections. The following examples illustrate various
techniques for accessing, referencing, and manipulating Illustrator objects.
Illustrator
®
CS2 Scripting
®
®
1

Advertisement

loading

Summary of Contents for Adobe 16001500 - Illustrator CS2 - Mac

  • Page 1: Accessing And Referencing Objects

    To make a script available as a menu item under Illustrator’s File>Scripts menu, place the script file in the directory Adobe Illustrator CS2\Presets\Scripts , then restart Illustrator. Each time you launch Illustrator, every script found in this location is added as a menu item ,Your script will be listed among the prebuilt Automation Scripts that are available in this directory.
  • Page 2 GettingStarted Illustrator JavaScript Example 1: Acting on Selected Objects When the user makes a selection in a displayed document, the selected objects are stored in the document’s selection property. To access all selected objects in the active document: var selectedObjects = app.activeDocument.selection; Depending on what is selected, the property value can be either an array of art objects or a text string.
  • Page 3 GettingStarted Illustrator JavaScript 8. If no document is open, set the message to reflect that case. else msgType = "No document Open."; 9. Finally, print the message. alert( msgType ); 10. Save the file. 11. Run the script, as described in Executing JavaScript Scripts above.
  • Page 4 GettingStarted Illustrator JavaScript 5. If no document is open, set the message to reflect that case. else msg = "No document Open."; 6. Print the msg. alert ( msg ); 7. Save the file. To run this example: 1. Launch Illustrator. 2.
  • Page 5 GettingStarted Illustrator JavaScript 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] );...
  • Page 6 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.

This manual is also suitable for:

Illustrator cs2