### Example: Create RGB Document Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Documents.md A practical example demonstrating the creation of a new Illustrator document with an RGB color space using the add() method. ```javascript // Creates a new document with an RGB color space app.documents.add(DocumentColorSpace.RGB); ``` -------------------------------- ### Getting a Spot Color by Index Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Spots.md Provides an example of accessing a SpotColor from the collection using its index. ```javascript app.activeDocument.spots.index(itemKey) ``` -------------------------------- ### Example: Creating a Symbol Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Symbols.md Demonstrates how to create a new symbol from a path item in Illustrator scripting. ```APIDOC ## Example: Creating a Symbol ### Description Creates a path item from each graphic style, then adds each item as a new symbol. ```javascript // Creates a path item from each graphic style // then adds each item as a new symbol var docRef = documents.add(); var y = 750; var x = 25; var iCount = docRef.graphicStyles.length; for (var i=0; i 0 ) { var doc = app.activeDocument; // Create the new spot var newSpot = doc.spots.add(); // Define the new color value var newColor = new CMYKColor(); newColor.cyan = 35; newColor.magenta = 0; newColor.yellow = 50; newColor.black = 0; // Define a new SpotColor with an 80% tint // of the new Spot's color. The spot color can then // be applied to an art item like any other color. newSpot.name = "Pea-Green"; newSpot.colorType = ColorModel.SPOT; newSpot.color = newColor; var newSpotColor = new SpotColor(); newSpotColor.spot = newSpot; newSpotColor.tint = 80; } ``` ``` -------------------------------- ### Example: Using Character Styles Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/CharacterStyles.md Demonstrates how to create, configure, and apply character styles to text frames using scripting. ```javascript ```javascript // Creates 3 text frames in a new document then creates // a character style and applies it to each text frame. var docRef = documents.add(); var textRef1 = docRef.textFrames.add(); textRef1.contents = "Scripting is fun!"; textRef1.top = 700; textRef1.left = 50; var textRef2 = docRef.textFrames.add(); textRef2.contents = "Scripting is easy!"; textRef2.top = 625; textRef2.left = 100; var textRef3 = docRef.textFrames.add(); textRef3.contents = "Everyone should script!"; textRef3.top = 550; textRef3.left = 150; redraw(); // Create a new character style var charStyle = docRef.characterStyles.add("BigRed"); // set character attributes var charAttr = charStyle.characterAttributes; charAttr.size = 40; charAttr.tracking = -50; charAttr.capitalization = FontCapsOption.ALLCAPS; var redColor = new RGBColor(); redColor.red = 255; redColor.green = 0; redColor.blue = 0; charAttr.fillColor = redColor; // apply to each textFrame in the document charStyle.applyTo(textRef1.textRange); charStyle.applyTo(textRef2.textRange); charStyle.applyTo(textRef3.textRange); ``` ``` -------------------------------- ### Example: Finding and Deleting Layers Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Layers.md Demonstrates how to iterate through layers in all open documents and delete layers whose names start with 'Temp'. ```APIDOC ## Example: Finding and Deleting Layers ### Description Deletes all layers whose name begins with "Temp" in all open documents. ### Code ```javascript // Deletes all layers whose name begins with "Temp" in all open documents var layersDeleted = 0; for (var i = 0; i < app.documents.length; i++) { var targetDocument = app.documents[i]; var layerCount = targetDocument.layers.length; // Loop through layers from the back, to preserve index // of remaining layers when we remove one for (var ii = layerCount - 1; ii >= 0; ii--) { var targetLayer = targetDocument.layers[ii]; var layerName = new String(targetLayer.name); if (layerName.indexOf("Temp") == 0) { targetDocument.layers[ii].remove(); layersDeleted++; } } } ``` ``` -------------------------------- ### Example: Toggling Selection State Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/PlacedItem.md Demonstrates how to toggle the selection state of all placed items in the active document. ```APIDOC ## Example: Toggling Selection State ### Description This script toggles the selection state of all placed items within the active Adobe Illustrator document. ### Method GET (Illustrative example for script execution) ### Endpoint N/A (Client-side script) ### Parameters None ### Request Example ```javascript // Toggles the selection state of all placed items. if (app.documents.length > 0) { for (i = 0; i < app.activeDocument.placedItems.length; i++) { var placedArt = app.activeDocument.placedItems[i]; placedArt.selected = !(placedArt.selected); } } ``` ### Response N/A (Modifies document state directly) ``` -------------------------------- ### Exporting to PNG24 format Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/ExportOptionsPNG24.md Example of how to export a document to PNG24 format with custom options. ```APIDOC ## Export to PNG24 ### Description Exports the current document to a PNG24 file with specified options. ### Method `Document.exportFile()` ### Parameters (within exportOptionsPNG24 object) - **antiAliasing** (Boolean) - Set to `false` to disable anti-aliasing. - **transparency** (Boolean) - Set to `false` to disable transparency. - **saveAsHTML** (Boolean) - Set to `true` to save with an accompanying HTML file. ### Request Example ```javascript // Exports current document to dest as a PNG24 file with specified options, // dest contains the full path including the file name, // saveAsHTML option creates an HTML version with the PNG file in an images folder function exportFileToPNG24(dest) { if (app.documents.length > 0) { var exportOptions = new ExportOptionsPNG24(); exportOptions.antiAliasing = false; exportOptions.transparency = false; exportOptions.saveAsHTML = true; var type = ExportType.PNG24; var fileSpec = new File(dest); app.activeDocument.exportFile(fileSpec, type, exportOptions); } } ``` ``` -------------------------------- ### Creating and Applying Spot Colors Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Spots.md A comprehensive example showing how to define a new spot color, add it to the document, and apply it to a path item with a specified tint. ```javascript // Defines and applies a new spot color in the current document, // then applies the color to the first path item if (app.documents.length > 0 && app.activeDocument.pathItems.length > 0) { // Define the new color value var newRGBColor = new RGBColor(); newRGBColor.red = 255; newRGBColor.green = 0; newRGBColor.blue = 0; // Create the new spot var newSpot = app.activeDocument.spots.add(); // Define the new SpotColor as 80% of the RGB color newSpot.name = "Scripted Red spot"; newSpot.tint = 80; newSpot.color = newRGBColor; // Apply a 50% tint of the new spot color to the frontmost path item. // Create a spotcolor object, set the tint value, var newSpotColor = new SpotColor(); newSpotColor.spot = newSpot; newSpotColor.tint = 50; // Use the spot color to set the fill color var frontPath = app.activeDocument.pathItems[0]; frontPath.filled = true; frontPath.fillColor = newSpotColor; } ``` -------------------------------- ### Getting a Spot Color by Name Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Spots.md Illustrates how to retrieve a SpotColor from the collection by its name. ```javascript app.activeDocument.spots.getByName(name) ``` -------------------------------- ### Setting print paper options Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/PrintPaperOptions.md Example of how to create and configure PrintPaperOptions for a print job. ```APIDOC ## Example: Setting print paper options ### Description This example demonstrates setting custom paper options for a print job in Adobe Illustrator. ### Code ```javascript // Creates a new document, adds a path item, applies a graphic style // then prints with specified paper options var docRef = documents.add(); var pathRef = docRef.pathItems.rectangle(600, 200, 200, 200); docRef.graphicStyles[1].applyTo(pathRef); var paperOpts = new PrintPaperOptions; var printOpts = new PrintOptions; printOpts.paperOptions = paperOpts; var printerCount = printerList.length; if (printerCount > 0) { // Print with the 1st paper from the 1st printer for (var i = 0; i < printerList.length; i++) { if (printerList[i].printerInfo.paperSizes.length > 0) { var printerRef = printerList[i]; } var paperRef = printerRef.printerInfo.paperSizes[0]; if (printerRef.printerInfo.paperSizes.length > 0){ paperOpts.name = paperRef.name; printOpts.printerName = printerRef.name; docRef.print(printOpts); } } } ``` ``` -------------------------------- ### SpotColor Management Example Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Spots.md Illustrates how to remove all existing spot colors from the current document and how to create a new spot color, define its properties (name, tint, color), and apply it to a path item. ```APIDOC ## SpotColor Management Examples ### Removing All Spot Colors ```javascript // Deletes all spots colors from the current document if ( app.documents.length > 0 ) { var spotCount = app.activeDocument.spots.length; if (spotCount > 0) { app.activeDocument.spots.removeAll(); } } ``` ### Creating and Applying Spot Colors ```javascript // Defines and applies a new spot color in the current document, then applies the color to the first path item if (app.documents.length > 0 && app.activeDocument.pathItems.length > 0) { // Define the new color value var newRGBColor = new RGBColor(); newRGBColor.red = 255; newRGBColor.green = 0; newRGBColor.blue = 0; // Create the new spot var newSpot = app.activeDocument.spots.add(); // Define the new SpotColor as 80% of the RGB color newSpot.name = "Scripted Red spot"; newSpot.tint = 80; newSpot.color = newRGBColor; // Apply a 50% tint of the new spot color to the frontmost path item. // Create a spotcolor object, set the tint value, var newSpotColor = new SpotColor(); newSpotColor.spot = newSpot; newSpotColor.tint = 50; // Use the spot color to set the fill color var frontPath = app.activeDocument.pathItems[0]; frontPath.filled = true; frontPath.fillColor = newSpotColor; } ``` ``` -------------------------------- ### Create Document from Preset Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Documents.md Creates a new Illustrator document based on a predefined startup preset. Optionally, it can use specific preset settings and control the visibility of the options dialog. ```javascript app.documents.addDocument(startupPreset[, presetSettings][, showOptionsDialog]) ``` -------------------------------- ### Get Paragraphs Typename Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Paragraphs.md Gets the class name of the Paragraphs collection. Accessing the collection by index is required. ```javascript app.activeDocument.textFrames[index].paragraphs.typename ``` -------------------------------- ### Documents.index() Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Documents.md Gets an element from the collection by its key. ```APIDOC ## GET /documents/index ### Description Gets an element from the collection. ### Method GET ### Endpoint /documents/index ### Parameters #### Query Parameters - **itemKey** (String or Number) - Required - String or number key of the element ### Request Example ```javascript { "itemKey": 0 } ``` ### Response #### Success Response (200) - **document** (Document) - The document at the specified index or key #### Response Example ```json { "document": "[Document Object Reference]" } ``` ``` -------------------------------- ### Displaying tab stop information Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/TabStopInfo.md An example script demonstrating how to retrieve and display tab stop information from text frames in an Illustrator document. ```APIDOC ## Example: Displaying tab stop information ```javascript // Displays tab stop information found in each text frame // of current document, if any. var docRef = app.activeDocument; var sData = "Tab Stops Found \t\tTabStop Leader\t\tTabStop Position\r"; var textRef = docRef.textFrames; for( var i=0 ; i < textRef.length; i++ ) { // Get all paragraphs in the textFrames var paraRef = textRef[i].paragraphs; for ( p=0 ; p < paraRef.length ; p++ ) { // Get para attributes for all textRanges in paragraph var attrRef = paraRef[p].paragraphAttributes; var tabRef = attrRef.tabStops; if ( tabRef.length > 0 ) { for(var t=0; t 0) { // Create a color for both ends of the gradient var startColor = new RGBColor(); startColor.red = 0; startColor.green = 100; startColor.blue = 255; var endColor = new RGBColor(); endColor.red = 220; endColor.green = 0; endColor.blue = 100; // Create a new gradient // A new gradient always has 2 stops var newGradient = app.activeDocument.gradients.add(); newGradient.name = "NewGradient"; newGradient.type = GradientType.LINEAR; // Modify the first gradient stop newGradient.gradientStops[0].rampPoint = 30; newGradient.gradientStops[0].midPoint = 60; newGradient.gradientStops[0].color = startColor; // Modify the last gradient stop newGradient.gradientStops[1].rampPoint = 80; newGradient.gradientStops[1].color = endColor; // construct an Illustrator.GradientColor object referring to the newly created gradient var colorOfGradient = new GradientColor(); colorOfGradient.gradient = newGradient; // get first path item, apply new gradient as its fill var topPath = app.activeDocument.pathItems[0]; topPath.filled = true; topPath.fillColor = colorOfGradient; } ``` ``` -------------------------------- ### Documents.addDocument() Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Documents.md Creates a document from the preset, replacing any provided setting values, and returns a reference to the new document. ```APIDOC ## POST /documents/addDocument ### Description Creates a document from the preset, replacing any provided setting values, and returns a reference to the new document. ### Method POST ### Endpoint /documents/addDocument ### Parameters #### Query Parameters - **startupPreset** (String) - Required - Startup preset to use - **presetSettings** (DocumentPreset) - Optional - Preset document template - **showOptionsDialog** (Boolean) - Optional - Whether to show options dialog ### Request Example ```javascript { "startupPreset": "Print", "presetSettings": { "colorMode": "CMYK", "units": "Inches" }, "showOptionsDialog": false } ``` ### Response #### Success Response (200) - **document** (Document) - Reference to the newly created document #### Response Example ```json { "document": "[Document Object Reference]" } ``` ``` -------------------------------- ### Get Paragraph by Index Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Paragraphs.md Retrieves a specific paragraph from the collection using its string or numeric index. ```javascript app.activeDocument.textFrames[index].paragraphs.index(itemKey) ``` -------------------------------- ### Illustrator Scripting: Get an artboard by name Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Artboards.md Retrieves the first artboard in the collection that matches the provided name. Useful for accessing a specific artboard when its name is known. ```javascript var artboardName = "MyArtboard"; var specificArtboard = app.activeDocument.artboards.getByName(artboardName); ``` -------------------------------- ### Get Document Width Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Document.md Retrieves the width of the currently active document in Illustrator. This property is read-only. ```javascript var currentDocumentWidth = app.activeDocument.width; ``` -------------------------------- ### Create New Illustrator Document with Text (VBScript) Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/scriptingVBScript/yourFirstScript.md This script creates a new Illustrator document, adds a text frame, and sets its content to "Hello World!". It requires the Illustrator application to be installed. ```vbscript Rem Hello World Set appRef = CreateObject("Illustrator.Application") Rem Create a new document and assign it to a variable Set documentRef = appRef.Documents.Add Rem Create a new text frame item and assign it to a variable Set sampleText = documentRef.TextFrames.Add Rem Set the contents and position of the TextFrame sampleText.Position = Array(200, 200) sampleText.Contents = "Hello World!" ``` -------------------------------- ### Example: Applying a graphic style Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/GraphicStyle.md A JavaScript example demonstrating how to duplicate path items, group them, and apply a graphic style. ```APIDOC ## Example: Applying a graphic style ### Code Snippet ```javascript // Duplicates each path item in the selection, places the duplicate into a new group, t// then applies a graphic style to the new groups items if (app.documents.length > 0) { var doc = app.activeDocument; var selected = doc.selection; var newGroup = doc.groupItems.add(); newGroup.name = "NewGroup"; newGroup.move(doc, ElementPlacement.PLACEATEND); var endIndex = selected.length; for (var i = 0; i < endIndex; i++) { if (selected[i].typename == "PathItem") selected[i].duplicate(newGroup, ElementPlacement.PLACEATEND); } for (i = 0; i < newGroup.pageItems.length; i++) { doc.graphicStyles[1].applyTo(newGroup.pageItems[i]); } } ``` ``` -------------------------------- ### Access PlacedItem Width - JavaScript Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/PlacedItem.md Gets the width of a placed item. This property is a read-only number (double). ```JavaScript app.activeDocument.placedItems[index].width ``` -------------------------------- ### PlacedItem Properties Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/PlacedItem.md Overview of the properties available for the PlacedItem object. ```APIDOC ## PlacedItem Properties ### `uRL` **Description**: The value of the Adobe URL tag assigned to this item. **Type**: String ### `visibilityVariable` **Description**: The visibility variable bound to the item. **Type**: [Variable](./Variable.md) ### `visibleBounds` **Description**: The visible bounds of the item including stroke width. **Type**: Array of 4 numbers; read-only. ### `width` **Description**: The width of the item. **Type**: Number (double) ### `wrapInside` **Description**: If `true`, the text frame object should be wrapped inside this object. **Type**: Boolean ### `wrapOffset` **Description**: The offset to use when wrapping text around this object. **Type**: Number (double) ### `wrapped` **Description**: If `true`, wrap text frame objects around this object (text frame must be above the object). **Type**: Boolean ### `zOrderPosition` **Description**: The position of this item within the stacking order of the group or layer (`parent`) that contains the item. **Type**: Number; read-only. ``` -------------------------------- ### Access InsertionPoints.parent Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/InsertionPoints.md Gets the container object for the InsertionPoints collection. This property is read-only and returns an Object. ```javascript app.activeDocument.textFrames[index].insertionPoints.parent ``` -------------------------------- ### Document.importPDFPreset() Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Document.md Loads PDF presets from a file, with an option to replace existing presets. ```APIDOC ## POST /app/activeDocument/importPDFPreset ### Description Loads all PDF presets from a file. ### Method POST ### Endpoint /app/activeDocument/importPDFPreset ### Parameters #### Request Body - **fileSpec** (File) - Required - File to load PDF presets from - **replacingPreset** (string) - Optional - Whether to replace existing presets ### Response #### Success Response (200) - **status** (string) - Indicates the operation was successful. #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Illustrator Scripting: Demonstrating Object Class Syntax Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/javascript-object-reference.md Illustrates the syntax and typical workflow for using Illustrator's object classes through sample JavaScript code. These examples focus on demonstrating syntax and may omit error checking or efficiency considerations. ```javascript // Sample code to illustrate the syntax and typical workflow usage of the object class. // Error checking, for instance, is generally brief or missing. // However, the examples can be combined and expanded to make scripts with greater functionality. ``` -------------------------------- ### Get Gradient Type Name Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Gradients.md Returns the class name of the gradients collection as a String. This property is read-only. ```javascript app.activeDocument.gradients.typename ``` -------------------------------- ### Illustrator PlacedItem Sliced Property Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/PlacedItem.md Gets or sets whether a placed item is sliced. The default value is false. ```javascript app.activeDocument.placedItems[index].sliced ``` -------------------------------- ### Example: Copying Mesh Items Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/MeshItems.md A JavaScript example demonstrating how to copy all mesh items from one open document to another. ```APIDOC ## Example: Copying Mesh Items This script copies all mesh items from the first open document to a newly created document. The copied items are offset on the y-axis. ```javascript // Copies all mesh items from one document to a new document if (app.documents.length > 0) { var srcDoc = documents[0]; var locationOffset = 0; var targetDoc = documents.add(); for (var i = 0; i < srcDoc.meshItems.length; i++) { var srcItem = srcDoc.meshItems[i]; var dupItem = srcDoc.meshItems[i].duplicate(targetDoc, ElementPlacement.PLACEATEND); // offset the copied items' position on the y axis dupItem.position = Array(100, 50 + locationOffset); locationOffset += 50; } } ``` ``` -------------------------------- ### Document.importPrintPreset() Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Document.md Loads a specific named print preset from a file. ```APIDOC ## POST /app/activeDocument/importPrintPreset ### Description Loads the named print preset from the file. ### Method POST ### Endpoint /app/activeDocument/importPrintPreset ### Parameters #### Request Body - **printPreset** (string) - Required - Name of preset to load - **fileSpec** (File) - Required - File to load print presets from ### Response #### Success Response (200) - **status** (string) - Indicates the operation was successful. #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Illustrator PlacedItem Name Property Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/PlacedItem.md Gets or sets the name of a placed item. The name is a string identifier for the item. ```javascript app.activeDocument.placedItems[index].name ``` -------------------------------- ### TracingOptions.storeToPreset() Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/TracingOptions.md Saves the current tracing options to a specified preset. ```APIDOC ## TracingOptions.storeToPreset() ### Description Saves this set of options in the specified preset. Use a name found in the `Application.tracingPresetList` array, or a new name to create a new preset. For an existing preset, overwrites an unlocked preset and returns `true`. Returns `false` if the preset is locked. ### Method Method ### Endpoint `image.tracing.tracingOptions.storeToPreset(parameter)` ### Parameters #### Path Parameters - **presetName** (String) - Required - Preset name to save as ### Returns Boolean ``` -------------------------------- ### Get Illustrator Pattern Parent Document Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Pattern.md Returns the Document object that contains the specified pattern. This is a read-only property. ```javascript app.activeDocument.patterns[index].parent ``` -------------------------------- ### Setting Print Options Example Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/PrintOptions.md Demonstrates how to create and configure a PrintOptions object with various sub-options and then use it to print a document. ```APIDOC ## Setting print options ### Description Creates a new document, adds symbols, specifies a variety of print options, assigns each print option to a PrintOptions object, then prints with those options. ### Request Example ```javascript // Creates a new document, adds symbols, specifies a variety of print options, // assigns each print option to a PrintOptions object, // then prints with those options // Create a new document and add some symbol items var docRef = documents.add(); var y = docRef.height - 30; for (var i = 0; i < (docRef.symbols.length); i++) { symbolRef = docRef.symbols[i]; symbolItemRef1 = docRef.symbolItems.add(symbolRef); symbolItemRef1.top = y; symbolItemRef1.left = 100; y -= (symbolItemRef1.height + 10); } redraw(); // Create multiple options and assign to PrintOptions var options = new PrintOptions(); var colorOptions = new PrintColorManagementOptions(); colorOptions.name = "ColorMatch RGB"; colorOptions.intent = PrintColorIntent.SATURATIONINTENT; options.colorManagementOptions = colorOptions; var printJobOptions = new PrintJobOptions(); printJobOptions.designation = PrintArtworkDesignation.ALLLAYERS; printJobOptions.reverse = true; options.jobOptions = printJobOptions; var coordinateOptions = new PrintCoordinateOptions(); coordinateOptions.fitToPage = true; options.coordinateOptions = coordinateOptions; var flatOpts = new PrintFlattenerOptions(); flatOpts.ClipComplexRegions = true; flatOpts.GradientResoultion = 60; flatOpts.RasterizatonResotion = 60; options.flattenerOptions = flatOpts; // Print with options docRef.print(options); ``` ``` -------------------------------- ### Get Paragraph Collection Length Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Paragraphs.md Retrieves the number of paragraphs in a text frame. Accessing the collection by index is required. ```javascript app.activeDocument.textFrames[index].paragraphs.length ``` -------------------------------- ### Access PlacedItem Visibility Variable - JavaScript Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/PlacedItem.md Gets the visibility variable bound to a placed item. The type is a Variable object. ```JavaScript app.activeDocument.placedItems[index].visibilityVariable ``` -------------------------------- ### Create Document Without UI Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Documents.md Programmatically creates a new Illustrator document using a specified startup preset without displaying any user interface elements for document creation. ```javascript app.documents.addDocumentNoUI(startupPreset) ``` -------------------------------- ### Illustrator PlacedItem Selected Property Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/PlacedItem.md Gets or sets the selection state of a placed item. If true, the item is selected; otherwise, it is not. ```javascript app.activeDocument.placedItems[index].selected ``` -------------------------------- ### Application.showPresets() Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Application.md Retrieves presets from a specified file. ```APIDOC ## Application.showPresets(fileSpec) ### Description Gets presets from the file. ### Parameters #### Path Parameters - **fileSpec** (File object) - Required - File to get presets from ### Returns PrintPresetList ``` -------------------------------- ### Display PPD File Info, Screens, and Spot Functions using JavaScript Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/PPDFileInfo.md This script retrieves and displays detailed information for the first 10 PPD files found, including their PostScript level, file paths, associated screens (name, angle, frequency), and screen spot functions (name, spot function type). The information is output to text frames in a new Illustrator document. ```javascript // Displays in a new text frame, the postscript level, file paths, screens, and // screen spot information for first 10 PPD files found var sPPD = ""; var docRef = documents.add(); var x = 30; var y = (docRef.height - 30); var iLength = PPDFileList.length; if (iLength > 10) iLength = 10; for (var i = 0; i < iLength; i++) { var ppdRef = PPDFileList[i]; sPPD = ppdRef.name; sPPD += "\r\tPS Level "; var ppdInfoRef = ppdRef.PPDInfo; sPPD += ppdInfoRef.languageLevel; sPPD += "\r\tPath: "; sPPD += ppdInfoRef.PPDFilePath; sPPD += "\r\tScreens:\r"; var iScreens = ppdInfoRef.screenList.length; for (var c = 0; c < iScreens; c++) { var screenRef = ppdInfoRef.screenList[c]; sPPD += "\t\t"; sPPD += screenRef.name; var screenInfoRef = screenRef.screenInfo; sPPD += ", Angle = "; sPPD += screenInfoRef.angle; sPPD += ", Frequency = "; sPPD += screenInfoRef.frequency; sPPD += "\r"; } sPPD += "\r\tScreenSpots:\r"; var iScreenSpots = ppdInfoRef.screenSpotFunctionList.length; for (var n = 0; n < iScreenSpots; n++) { var screenSpotRef = ppdInfoRef.screenSpotFunctionList[n]; sPPD += "\t\t"; sPPD += screenSpotRef.name; sPPD += ", spotFunction: "; sPPD += screenSpotRef.spotFunction; sPPD += "\r"; } var textRef = docRef.textFrames.add(); textRef.textRange.characterAttributes.size = 8; textRef.contents = sPPD; textRef.top = (y); textRef.left = x; redraw(); y -= (textRef.height); } ``` -------------------------------- ### Illustrator PlacedItem Locked Property Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/PlacedItem.md Gets or sets the locked state of a placed item. If true, the item is locked and cannot be modified. ```javascript app.activeDocument.placedItems[index].locked ``` -------------------------------- ### Illustrator Scripting Examples Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/RasterItems.md Provides practical examples of how to use the RasterItems collection in Adobe Illustrator scripting. ```APIDOC ## Examples ### Creating a raster item ```javascript // Creates a new raster item in a new document from a raster file // jpgFilePath contains the full path and file name of a jpg file function createRasterItem(jpgFilePath) { var rasterFile = File(jpgFilePath); var myDoc = app.documents.add(); var myPlacedItem = myDoc.placedItems.add(); myPlacedItem.file = rasterFile; myPlacedItem.position = Array(0, myDoc.height); myPlacedItem.embed(); } ``` ### Finding and examining a raster item ```javascript // Examines the color space of the first raster item in the document and displays // result in ESTK console if (app.documents.length > 0 && app.activeDocument.rasterItems.length > 0) { var rasterArt = app.activeDocument.rasterItems[0]; switch (rasterArt.imageColorSpace) { case ImageColorSpace.CMYK: $.writeln("The color space of the first raster item is CMYK"); break; case ImageColorSpace.RGB: $.writeln("The color space of the first raster item is RGB"); break; case ImageColorSpace.GRAYSCALE: $.writeln("The color space of the first raster item is GRAYSCALE"); break; } } ``` ``` -------------------------------- ### Illustrator PlacedItem Layer Property Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/PlacedItem.md Gets the layer to which a placed item belongs. This property is read-only and returns a Layer object. ```javascript app.activeDocument.placedItems[index].layer ``` -------------------------------- ### Illustrator PlacedItem Hidden Property Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/PlacedItem.md Gets or sets the visibility of a placed item. If true, the item is hidden; otherwise, it is visible. ```javascript app.activeDocument.placedItems[index].hidden ``` -------------------------------- ### Initialize PrintJobOptions Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/PrintJobOptions.md Demonstrates how to create a new instance of the PrintJobOptions class, which holds settings for printing jobs. ```javascript new PrintJobOptions() ``` -------------------------------- ### Get Paragraph Parent Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Paragraphs.md Returns the parent object of the Paragraphs collection, typically a TextFrame. Accessing the collection by index is required. ```javascript app.activeDocument.textFrames[index].paragraphs.parent ``` -------------------------------- ### Example: Importing a PDF as a group item Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/GroupItems.md Demonstrates how to use the `createFromFile` method to import a PDF as a group item. ```APIDOC ## Example: Importing a PDF as a group item ### Description The following script shows how you can import a PDF document using the [GroupItems.createFromFile()](#groupitemscreatefromfile) function. !!! note Before running this script you must create a one page PDF file and put it in the location `/temp/testfile1.pdf`. ### Code ```javascript // Embeds a new group item in to the current document from a file specified by dest // dest should contain the full path and file name function embedPDF(dest) { var embedDoc = new File(dest); if (app.documents.length > 0 && embedDoc.exists) { var doc = app.activeDocument; var placed = doc.groupItems.createFromFile(embedDoc); } } ``` ``` -------------------------------- ### Create Illustrator document and "Hello World" text frame (JavaScript) Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/scriptingJavascript/yourFirstScript.md This script creates a new Adobe Illustrator document and adds a text frame containing the "Hello World!" message. It demonstrates basic document and text frame manipulation using the Illustrator scripting API. ```javascript //Hello World! var myDocument = app.documents.add(); //Create a new text frame and assign it to the variable "myTextFrame" var myTextFrame = myDocument.textFrames.add(); // Set the contents and position of the text frame myTextFrame.position = [200,200]; myTextFrame.contents = "Hello World!" ``` -------------------------------- ### Get Gradient Parent Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Gradients.md Returns the parent object of the gradients collection. This property is read-only and returns a generic Object type. ```javascript app.activeDocument.gradients.parent ``` -------------------------------- ### PluginItem Properties Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/PluginItem.md This section covers the various properties of the PluginItem object, which provide information about its visibility, bounds, dimensions, and wrapping behavior. ```APIDOC ## PluginItem Properties ### `visibilityVariable` **Description**: The visibility variable bound to the item. **Type**: [Variable](./Variable.md) ### `visibleBounds` **Description**: The visible bounds of the item including stroke width. **Type**: Array of 4 numbers; read-only. ### `width` **Description**: The width of the item. **Type**: Number (double) ### `wrapInside` **Description**: If `true`, the text frame object should be wrapped inside this object. **Type**: Boolean ### `wrapOffset` **Description**: The offset to use when wrapping text around this object. **Type**: Number (double) ### `wrapped` **Description**: If `true`, wrap text frame objects around this object (text frame must be above the object). **Type**: Boolean ### `zOrderPosition` **Description**: The position of this item within the stacking order of the group or layer (`parent`) that contains the item. **Type**: Number; read-only. ``` -------------------------------- ### Create Illustrator Application Instance (VBScript) Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/scripting/launching.md This VBScript code shows how to create an instance of the Illustrator application using `CreateObject`. It can launch Illustrator invisibly, requiring manual activation for visibility. It also details version-specific identifiers. ```vbscript Set appRef = CreateObject("Illustrator.Application") ``` ```vbscript Set appRef = CreateObject("Illustrator.Application.CS6") ``` -------------------------------- ### Getting CharacterStyles Type Name Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/CharacterStyles.md Retrieves the class name of the character styles collection object. This is a read-only string property. ```javascript app.activeDocument.characterStyles.typename ``` -------------------------------- ### Get Datasets Type Name in Illustrator Scripting Source: https://github.com/docsforadobe/illustrator-scripting-guide/blob/master/docs/jsobjref/Datasets.md Returns the class name ('Datasets') of the collection. This is a read-only string property. ```javascript app.activeDocument.dataSets.typename ```