0

My intention is to create a script for Adobe Illustrator which calls a compiled C executable I wrote with some input parameters.

The C executable (named 'crowd-generator') will generate and return an array of x,y co-ordinates based on the input parameters.

As far as I can tell from the research I have done so far, I should be able to execute the code like this (ignoring input parameters for now):

#include crowd/crowd-generator

var script_file = new File('crowd/crowd-generator');
var result = script_file.execute();

However, all this seems to do it to open my executable file in ExtendScript and then tell me it has syntax errors in it, which it definitely doesn't. I think perhaps it is trying to run it as a .jsx file.

One thing I have tried is giving 'crowd-generator' a .app or .exe file extension. The only difference this makes is that when trying to run my script, I get a dialog box asking me what language the executable is in... then it gives me a syntax error anyway whatever I choose.

What is going wrong? Is there any way to run this executable from a .jsx file run in Adobe Illustrator?

Martha
  • 178
  • 1
  • 11

3 Answers3

2

What does this line mean?:

  #include crowd/crowd-generator

In fact, you are trying to include executible code into jsx file, this is the error.

emax
  • 511
  • 1
  • 4
  • 13
0

Unfortunatly Illustrator has not the nice functions like InDesigns app.doScript or After Effects system.callSystem.

One way to execute a command on macOS would be creating a term file.

/* global $, app, File */
/**
 * Read about termfiles
 * http://docstore.mik.ua/orelly/unix3/mac/ch01_03.htm
 * 1.3.1.1. .term files
 */

var termfile = new File(File($.fileName).parent.fsName + '/command.term');
var command = 'cd ' + File($.fileName).parent.fsName + ' ; ls';
termfile.open('w');

termfile.writeln(
    '<?xml version="1.0" encoding="UTF-8"?>\n' +
        '<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"' +
            '"http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n' +
            '<plist version="1.0">\n' +
                '<dict>\n' +
                    '<key>WindowSettings</key>\n' +
                '<array>\n' +
                ' <dict>\n' +
                '<key>CustomTitle</key>\n' +
                '<string>My first termfile</string>\n' +
                '<key>ExecutionString</key>\n' +
                '<string>' + command + '</string>\n' +
                '</dict>\n' +
                '</array>\n' +
                '</dict>\n' +
            '</plist>\n');

termfile.close();
termfile.execute();

Another way is creating a command file. This is just a shell script that you make executable chmod +x myScript.command and then you also call it with the execute command.

  • Create file myScript.command with a simple command in it, ls is enough for testing purpose.

It should look like this:

#!/bin/bash
ls
  • Open a terminal and navigate to the folder where the script is.
  • Make it executable by running chmod +x myScript.command
  • Create the script that executes it next to it.

This should be its content:

var commandFile = File(File($.fileName).parent.fsName + '/myScript.command');
commandFile.execute();

Execute it from Illustrator.


A problem will be to get return values.

fabianmoronzirfas
  • 4,091
  • 4
  • 24
  • 41
0

Since posting this question I have made some progress and have decided to post my answer.

There are 2 problems with my code.

The first, as emax correctly pointed out in their answer, I was mistakenly trying to include the executable file with the line:

#include crowd/crowd-generator

With this line removed, the code still didn't work - I realised after a bit of that this is because the ExtendScript FILE object needs an absolute file path instead of a relative one

source

So - my corrected code looks something like this:

var script_file = new File('/Applications/Adobe Illustrator CC 2015.3/Presets.localized/en_GB/Scripts/crowd/crowd-generator');
var result = script_file.execute();

Now I just need to figure out how to make that executable call with arguments, and get the result back.

Martha
  • 178
  • 1
  • 11
  • 1
    About passing args and getting return val you can read here http://stackoverflow.com/questions/42863672/passing-the-result-of-a-python-script-to-an-extendscript-jsx-file/42873262#42873262 – emax Apr 24 '17 at 11:14
  • @emax Thanks, very helpful. I think I have decided to go another route with this project now for other reasons, but this is excellent knowledge and surprisingly hard to find online. – Martha Apr 25 '17 at 09:00