illustrator scripting

Combining Illustrator Extension Technologies

How can developers combine Extension Technologies - CEP, Illustrator scripting (ExtendScript), and C++ plug-ins in Illustrator?

If you need to achieve speed and enhanced integration, the C++ interface probably represents the best route, as we demonstrated when integrating Illustrator into SMART boards. In other situations, you can use Adobe Illustrator scripts.

CEP

Common Extensibility Platform (CEP) is the standard way of providing a user interface in Adobe Illustrator scripts and uses web based technologies such as HTML and JavaScript. Event handling can be provided you with the C++ and ExtendScript interfaces for both commands and feedback.

Using CEP and ExtendScript together

Adobe Illustrator Scripts use CEP and ExtendScript that represent two separate Illustrator scripting technologies that a single source file cannot simultaneously support. In their distinct environments, Adobe Illustrator scripts – CEP and ExtendScript – leverage unique APIs and cater to different use cases. Typically, developers use ExtendScript for back-end automation and batch processing within a specific Adobe application’s context. Conversely, CEP finds its use primarily in crafting custom UI elements and front-end functionality that operates in a browser-like setting. Including ExtendScript code within a CEP extension’s code is not possible, except as a mere text string. Similarly, running CEP code within an ExtendScript script is unfeasible. To incorporate both CEP and ExtendScript into your Illustrator scripting project, ideally, you should maintain two separate source files: one dedicated to CEP and the other to ExtendScript.

Calling ExtendScript from CEP

To call ExtendScript from a CEP extension, you can utilize the evalScript method offered by the CEP extension APIs. This approach enables the execution of ExtendScript Illustrator scripting code within the Adobe application, hosting the CEP extension. For instance, to execute an ExtendScript script from the JavaScript in a CEP extension, you can use the evalScript method by passing the code as a string, as demonstrated below:


var csInterface = new CSInterface();

function callExtendScript() {
    var script = "var doc = app.activeDocument; doc.artboards[0].name = 'New Name';";
    csInterface.evalScript(script, function(result) {
        console.log(result);
    });
}
			

In this case, the evalScript method is invoked with the ExtendScript script as its first argument. The second argument is a callback function that is invoked once the script has completed its execution. This callback function accepts a single parameter, which contains the script’s output. It’s important to note that the evalScript method is synchronous, which means it will halt the CEP extension execution until the ExtendScript script has completed. If your script takes a long time to execute, the user interface will become unresponsive.

CEP Folder Structure

This is the folder structure of a typical CEP extension:


MyExtension/
    CSXS/
        manifest.xml
    js/
        index.js
        myScript.js
    html/
        index.html
    css/
        styles.css
    assets/
        logo.png
        myScript.jsx
			

Also See Crafting Creative Solutions: Exploring the World of Adobe Illustrator Plugin Development

What next?

If you are interested in discussing our Illustrator scripting and software development further then please send an email to info@mapsoft.com