Adobe 65010248 - Illustrator CS4 - PC Manual

Scripting guide
Hide thumbs Also See for 65010248 - Illustrator CS4 - PC:
Table of Contents

Advertisement

Quick Links

ADOBE
ILLUSTRATOR
CS4
®
®
ADOBE ILLUSTRATOR CS4
SCRIPTING GUIDE

Advertisement

Table of Contents
loading

Summary of Contents for Adobe 65010248 - Illustrator CS4 - PC

  • Page 1 ADOBE ILLUSTRATOR ® ® ADOBE ILLUSTRATOR CS4 SCRIPTING GUIDE...
  • Page 2 Adobe Systems Incorporated. Please note that the content in this guide is protected under copyright law even if it is not distributed with software that includes an end user license agreement.
  • Page 3: Table Of Contents

    Script support in Adobe Illustrator CS4 ........
  • Page 4 Contents Scripting Illustrator ............25 Launching and quitting Illustrator from a script .
  • Page 5 Contents Creating paths and shapes ..............45 Paths .
  • Page 6: Introduction

    Introduction This guide describes the scripting interface to Adobe® Illustrator® CS4. If you are new to scripting or want basic information about scripting and how to use the different scripting languages, see Adobe Introduction to Scripting. What is scripting? A script is a series of commands that tells Illustrator to perform one or more tasks. These tasks can be simple, affecting only one object in the current document, or complex, affecting objects in all your Illustrator documents.
  • Page 7: Script Support In Adobe Illustrator Cs4

    For details of these and other features, see JavaScript Tools Guide. Script file extensions For a file to be recognized by Adobe Illustrator CS4 as a valid script file, the file must have the correct file name extension: Script type...
  • Page 8: Viewing Sample Scripts

    1: Introduction Viewing sample scripts 8 HAPTER Viewing sample scripts Adobe provides sample scripts for many objects, properties, and methods in the Illustrator CS4 DOM. You can view script samples in two locations: ➤ In the folder in your Illustrator CS4 installation directory /Scripting/Sample Scripts ➤...
  • Page 9: Viewing The Vbscript Object Model

    2. In the Visual Basic Editor, choose Tools > References. 3. In the dialog that appears, select the check box for Adobe Illustrator CS4 Type Library, and click OK. 4. Choose View > Object Browser, to display the Object Browser window.
  • Page 10: Installing Scripts In The Scripts Menu

    Only files that are of one of the supported file types are displayed in the browse dialog. For details, see “Script support in Adobe Illustrator CS4” on page Startup scripts (.jsx scripts only) JavaScript scripts with a file extension can be installed in one of two folders, so the scripts run .jsx...
  • Page 11: Changes Since Cs3

    The general startup scripts folder contains scripts that run automatically when you start any Creative Suite 4 application. You create the folder in the following location: ➤ Windows: Program Files/Common Files/Adobe/Startup Scripts CS4/Illustrator ➤ Mac OS: :Library:Application Support:Adobe:Startup Scripts CS4:Illustrator...
  • Page 12 1: Introduction Changes since CS3 12 HAPTER ➤ A new collection, , contains a collection of objects. NonNativeItems NonNativeItem ➣ AppleScript — non native items of document 1 ➣ JavaScript — app.activeDocument.nonNativeItems ➣ VBScript — App.ActiveDocument.NonNativeItems ➤ A new FXG file format supports designer-developer workflow, by allowing an Illustrator document to be saved as an FXG file containing XML-style descriptions of Illustrator graphical items, which can then be used in other FXG/XML-based applications.
  • Page 13 1: Introduction Changes since CS3 13 HAPTER ➤ A new , specifies metrics-Roman-only kerning. AutoKernType MetricsRomanOnly ➣ AppleScript — character: MetricsRomanOnly character style: MetricsRomanOnly line: MetricsRomanOnly paragraph: MetricsRomanOnly paragraph style: MetricsRomanOnly word: MetricsRomanOnly ➣ JavaScript — AutoKernType.METRICSROMANONLY ➣ VBScript — AiAutoKernType.aiMetricsRomanOnly ➤...
  • Page 14 1: Introduction Changes since CS3 14 HAPTER ➤ Two new methods were added to the class. captures the current document Document WindowCapture to a TIFF image. rasterizes the source art within a specified clip bounds. Rasterize ➣ AppleScript — capture document 1 rasterize document 1 ➣...
  • Page 15 1: Introduction Changes since CS3 15 HAPTER ➤ A new class, , defines an artboard object or artboard in a CS4 document. It has the following Artboard properties: ArtboardRect RulerPAR ShowRulers ShowCenter ShowCrossHairs ShowSafeAreas ShowScreenEdge ➣ JavaScript — app.activeDocument.artboards[0] ➣ AppleScript —...
  • Page 16: Known Issues

    1: Introduction Known issues 16 HAPTER Known issues ➤ Scripts that create, save, and close many Illustrator files should periodically quit and relaunch Illustrator. The recommended maximum number of files to process before quitting and relaunching Illustrator is: ➣ Windows 500 files ➣...
  • Page 17: The Illustrator Scripting Object Model

    The Illustrator Scripting Object Model A good understanding of the Illustrator object model will improve your scripting abilities. The following figure shows the containment hierarchy of the object model, starting with the object. Note application that the classes can contain nested objects of the same class which can, in turn, layer group item contain additional nested objects.
  • Page 18: Object-Naming Conventions

    2: The Illustrator Scripting Object Model Object-naming conventions 18 HAPTER Object-naming conventions There is one object model for the Illustrator scripting interface, but actual object names vary slightly in the different scripting languages: ➤ AppleScript names are lower case, and individual words are separated by a space; for example: graphic style ➤...
  • Page 19: Document

    2: The Illustrator Scripting Object Model The artwork tree 19 HAPTER Document object, which your scripts can create or access through the object, represents document application an art canvas or loaded Illustrator file. The object’s properties give you access to the document’s document content;...
  • Page 20: Art Styles

    ➤ object legacy text items For details on creating objects of these types, see the Adobe Illustrator CS4 Scripting Reference for your language. Art styles Your script can apply a graphic style to artwork using the object. To apply a graphic style,...
  • Page 21: Color Objects

    2: The Illustrator Scripting Object Model Text objects 21 HAPTER Color objects Your script can apply a color, pattern or gradient to a object, using the path item fill color properties: stroke color ➤ Scripts can define new color swatches using the command or method of the make...
  • Page 22: Objects That Represent Text Content

    2: The Illustrator Scripting Object Model Text objects 22 HAPTER To create a specific kind of text frame, use the property of the object in AppleScript. The kind text frames JavaScript and VBScript objects contain specific methods for creating area text frames and text frames path text frames.
  • Page 23: Text Styles

    2: The Illustrator Scripting Object Model Text objects 23 HAPTER Both objects have properties. The text frame story insertion point text selection text object’s properties also include the defining features of the text frame, such as: frame ➤ The frame , and width height...
  • Page 24: Dynamic Objects

    2: The Illustrator Scripting Object Model Dynamic objects 24 HAPTER Dynamic objects By creating dynamic objects, you can create data-driven graphics. In the Illustrator application, you use the Variables panel to create or edit variables like graph data, linked file, text string, and visibility, or variables whose type is not specified.
  • Page 25: Scripting Illustrator

    Illustrator. The command activates Illustrator tell activate if it is not already active. tell application "Adobe Illustrator" activate end tell JavaScript Typically, you run JavaScript scripts from the application’s Scripts menu (File > Scripts) or start-up folder, so there is no need to launch Illustrator from your script.
  • Page 26: Quitting Illustrator

    There are other types of “active” or “current” object properties, like . For active dataset active view details, see the Adobe Illustrator CS4 Scripting Reference for your language. Creating new objects Several objects (besides the object itself ) cannot be obtained from containers or parent application objects.
  • Page 27: Collection Objects

    Adobe ExtendScript devices designed to provide platform-independent file folder access to the underlying file system. For information on using these objects, see JavaScript Tools Guide. For information on creating an object explicitly, see the chapter for your scripting language.
  • Page 28: Selected Objects

    Illustrator CS4 Scripting Reference: AppleScript or the Properties table in Adobe Illustrator CS4 Scripting Reference: JavaScript or Adobe Illustrator CS4 Scripting Reference: VBScript. A diagram of the Illustrator CS4 object model is in “The Illustrator Scripting Object Model” on page Selected objects Sometimes, you want to write scripts that act on the currently selected object or objects.
  • Page 29: Measurement Units

    3: Scripting Illustrator Measurement units 29 HAPTER Measurement units Illustrator uses points as the unit of measurement for almost all distances. One inch equals 72 points. The exception is values for properties like , and the properties (used for Japanese text kerning tracking composition), which use em units.
  • Page 30: Art Item Bounds

    3: Scripting Illustrator Page-item positioning and dimensions 30 HAPTER You can see these coordinates in the Info panel when you select or create an object in Illustrator. The default point (0, 0) for coordinate numbering in Illustrator is the lower-left corner of the ruler origin document.
  • Page 31: Paths And Shapes

    3: Scripting Illustrator Paths and shapes 31 HAPTER Paths and shapes Paths are represented in the Illustrator DOM by the object. Path items include all artwork that path item contains paths, such as rectangles, ellipses, and polygons, as well as freeform paths. A freeform path consists of a series of path points.
  • Page 32: Printing Illustrator Documents

    3: Scripting Illustrator Printing Illustrator documents 32 HAPTER The four values allow you to control interaction based on the source of the script commands. For example, if the application is acting as a server for remote users, it would be difficult for a remote user to dismiss a dialog, but it would be no problem for someone sitting in front of the machine.
  • Page 33: Scripting With Applescript

    “Viewing the AppleScript object model” on page If you do not understand the concepts and terms used in this chapter, read Adobe Introduction to Scripting. Your first Illustrator script The traditional first project in any programming language is displaying the message “Hello World!” In this example, you create a new Illustrator document, then add a text frame containing this message.
  • Page 34: Adding Features To "Hello World

    Follow these steps: 1. In Script Editor, choose File > New to create a new script. 2. Enter the following code: tell application "Adobe Illustrator" -- current document is always the active document set docRef to the current document set docWidth to the width of docRef...
  • Page 35: Obtaining Objects From Documents And Layers

    1 to {path item 1 of layer 1 of document 1, path item 1 of layer 1 of document 1} A better approach is to reference the objects by name: tell application "Adobe Illustrator" set newDocument to make new document make new rectangle in newDocument with properties {name:"rectangle"} make new star in newDocument with properties {name:"star"}...
  • Page 36: Working With Text Frames

    To find out an object’s type, use the property. class The following sample gets the first object in the array, then displays the object’s type: tell application "Adobe Illustrator" set myDoc to current document set selectedObjects to selection of myDoc set topObject to item 1 of selectedObjects...
  • Page 37: Creating Paths And Shapes

    The following script specifies three pairs of x-y coordinates, to create a path with three points: tell application "Adobe Illustrator" set docRef to make new document -- set stroked to true so we can see the path...
  • Page 38: Shapes

    4: Scripting with AppleScript Creating paths and shapes 38 HAPTER tell application "Adobe Illustrator" set docRef to make new document -- set stroked to true so we can see the path set lineRef to make new path item in docRef with properties {stroked:true}...
  • Page 39 For existing path-item objects, the properties are read-only properties whose values cannot be changed. Creating a rectangle Consider the following sample: tell application "Adobe Illustrator" set docRef to make new document set rectRef to make new rectangle in docRef with properties {bounds:{288, 360, 72, 144}}...
  • Page 40: Scripting With Javascript

    8 or JavaScript Tools Guide. If you do not understand the concepts and terms used in this chapter, read Adobe Introduction to Scripting. Your first Illustrator script The traditional first project in any programming language is displaying the message “Hello World!” In this example, you create a new Illustrator document, then add a text frame containing this message.
  • Page 41: Adding Features To "Hello World

    [,changeFillPatterns] [,changeFillGradients] [,changeStrokePattern] [,rotateAbout]) In the definition, taken from Adobe Illustrator CS4 Scripting Reference: JavaScript, optional parameters are enclosed in square brackets ( To rotate the object 30 degrees and change the , you would use the following script fillGradients statement: myObject.rotate(30, undefined, undefined, true);...
  • Page 42: Accessing And Referencing Objects

    5: Scripting with JavaScript Accessing and referencing objects 42 HAPTER Accessing and referencing objects When you write a script, you must first decide which file, or , the script should act on. Through document object, the script can create a new document, open an existing document, or act on a application document that is already open.
  • Page 43: Creating New Objects

    5: Scripting with JavaScript Accessing and referencing objects 43 HAPTER The following statements assign the name of the first graphic style in the collection to a variable. You can use these statements interchangeably. var styleName = myStyles[0].name var styleName = firstStyle.name var styleName = app.activeDocument.graphicStyles[0].name To get the total number of objects in a collection, use the property:...
  • Page 44: Working With Selections

    5: Scripting with JavaScript Working with text frames 44 HAPTER Working with selections When the user makes a selection in a document, the selected objects are stored in the document’s property. To access all selected objects in the active document: selection var selectedObjects = app.activeDocument.selection;...
  • Page 45: Creating Paths And Shapes

    5: Scripting with JavaScript Creating paths and shapes 45 HAPTER Threaded frames make a single story object Threaded frames make a single object. To observe this, run the following JavaScript after running story the script in “Threaded frames” on page var myDoc = app.activeDocument alert("There are "...
  • Page 46: Shapes

    5: Scripting with JavaScript Creating paths and shapes 46 HAPTER var myDoc = app.activeDocument; var myLine = myDoc.pathItems.add(); //set stroked to true so we can see the path myLine.stroked = true; var newPoint = myLine.pathPoints.add(); newPoint.anchor = [220, 475]; //giving the direction points the same value as the //anchor point creates a straight line segment newPoint.leftDirection = newPoint.anchor;...
  • Page 47 5: Scripting with JavaScript Creating paths and shapes 47 HAPTER 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 object’s method to create a rectangle with these properties: pathItems rectangle() ➤...
  • Page 48: Scripting With Vbscript

    Illustrator CS4 type library from most VBScript editors or any Microsoft Office application; see “Viewing the VBScript object model” on page If you do not understand the concepts and terms used in this chapter, read Adobe Introduction to Scripting. Your first Illustrator script The traditional first project in any programming language is displaying the message “Hello World!”...
  • Page 49: Adding Features To "Hello World

    6: Scripting with VBScript Accessing and referencing objects 49 HAPTER Adding features to “Hello World” Next, we create a new script that makes changes to the Illustrator document you created with your first script. The second script demonstrates how to: ➤...
  • Page 50: Creating New Objects

    6: Scripting with VBScript Accessing and referencing objects 50 HAPTER In the script below, the variable will not necessarily refer to the same object as the above pageItemRef script, since this script includes a reference to a layer: Set documentRef = appRef.ActiveDocument Set pageItemRef = documentRef.Layers(1).PageItems(1) VBScript indexes start at 1 for object collections;...
  • Page 51: Working With Text Frames

    6: Scripting with VBScript Working with text frames 51 HAPTER Working with text frames To create a text frame of a specific type in VBScript, use the method that corresponds to the TextFrames type of frame you want to create: Set rectRef = docRef.PathItems.Rectangle(700, 50, 100, 100) ' Use the AreaText method to create the text frame Set areaTextRef = docRef.TextFrames.AreaText(rectRef)
  • Page 52 6: Scripting with VBScript Creating paths and shapes 52 HAPTER Using x-y coordinates limits the path to straight segments. To created a curved path, you must create objects. Your path can comprise a combination of page coordinates and objects. PathPoint PathPoint Specifying a series of x-y coordinates To specify a path using page-coordinate pairs, use the...
  • Page 53: Shapes

    6: Scripting with VBScript Creating paths and shapes 53 HAPTER 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...
  • Page 54: Working With Enumeration Values

    “Viewing the VBScript object model” on page ➤ The Adobe Illustrator CS4 Scripting Reference: VBScript, which lists the numeral values directly after the constant value in the “Enumerations” chapter at the end of the book. The following example is from that table:...
  • Page 55: Index

    Illustrator control bounds, 30 launching, 25 coordinates, about, 29 quitting, 25 CS2 version changes, 16 specifying a version, 25 Illustrator, See Adobe Illustrator inches, conversion of measurements, 29 installing scripts, 10 datasets, using, 24 dialogs enabling, 31 suppressing, 31 JavaScript...
  • Page 56 Index matrices, about, 24 rectangles matrix class, 24 creating, 53 measurement values, 29 fixed, 30 methods, using, 41 references, object. See object references millimeters, conversion, 29 right direction, 31 object model script examples changes in Illustrator CS2, 16 creating a curved path, 37, 45, 52 diagram, 17 creating a path, 37, 45, 52 text, 21...
  • Page 57 Index units of measurement, 29 width, maximum value allowed, 29 user interaction levels, 31 write-once, 39 variables X axis, 29 deleting, 24 using, 24 VBScript Y axis, 29 enumeration values, 54 file extension, 7 naming conventions, 18 type library, 9 zero point, 29 versions of Illustrator, specifying, 25 visible bounds, 30...

This manual is also suitable for:

Illustrator cs4

Table of Contents