Skip to main content
Known Participant
January 31, 2010
Question

Modular scripting - howto

  • January 31, 2010
  • 1 reply
  • 911 views

Hi,

I'm having a hard time trying to implement a modular scripting approach in JS. I hope there's someone out there to guide me.

Basically, I want a set of my scripts to share a library of my own functions. What I'm trying is to make use of the #targetengine "session" statement, which is referred to in InD and Ai guides as the one to persist for an app session. And that's what I want to do: put my library in the startup scripts folder so that it loads first, and then any time user launches a tool script of my suite, it would benefit from a set of functions residing in the script engine.

The snippets from the Adobe pdfs however do not work. I'm getting "Cannot execute script in the 'session' engine" alerts.

I checked it with both Illustrator CS3 and InDesign CS3 (which are said to support #targetengine), with same poor result.

I tried also a snippet for declaring an engine (#engine library) found in the JS Tools pdf. This in turn won't compile, claiming an illegal use of reserved word 'export'.

Anyone got a clue what I'm doing wrong?

regards,

Moniuch

This topic has been closed for replies.

1 reply

Bob Stucky
Adobe Employee
Adobe Employee
January 31, 2010

Moniuch,

If you go to my site, www.creativescripting.net, and click the Free Stuff link, the top item is a "scripted extension" sample project.

It's a pretty full-featured example of one way to do modular coding in JS for InDesign projects.

Regards

Bob

moniuchAuthor
Known Participant
January 31, 2010

Thanks Bob,

I looked into your code and still do not understand why my code does not work.

Script put in /Adobe Illustrator CS3/Presets/Startup Scripts:

#target illustrator
#targetengine "session"

if(!lib) var lib = {};

lib.say = function(s){
        alert(s)
    }

Script launched by user:

#target illustrator

#targetengine "session"
lib.say('librarian');

I'm getting "Cannot execute script in 'session' engine" - or whatever I name the engine.

Regards,

Moniuch

Bob Stucky
Adobe Employee
Adobe Employee
January 31, 2010

Having never tried a persistent scripting engine in Illustrator, I'm not sure what's wrong. It could be that the persistent engine isn't being created.

After you launch AI with the start up script installed, open the ESTK, select Illustrator. If your engine was created it should show in the drop down menu of named scripting engines. If so, you should be able to run a script in that engine.

Regards

Bob