6 Replies Latest reply on Jan 31, 2010 2:04 PM by moniuch

    Modular scripting - howto

    moniuch Level 1

      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

        • 1. Re: Modular scripting - howto
          Bob Stucky Adobe Employee

          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

          • 2. Re: Modular scripting - howto
            moniuch Level 1

            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

            • 3. Re: Modular scripting - howto
              Bob Stucky Adobe Employee

              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

              • 4. Re: Modular scripting - howto
                moniuch Level 1

                That's indeed the case - the engine never gets created. I have only 'main' listed.

                However in InD I have some more - "export xhtml" and such. So apparantly there's something wrong with my Ai.

                Doh...

                 

                moniuch

                • 5. Re: Modular scripting - howto
                  Harbs. Level 6

                  You are running the script from the panel, and not ESTK. Right?

                   

                  (ESTK will not create the engine, and neither will a jsxbin file.)

                   

                  Harbs

                  • 6. Re: Modular scripting - howto
                    moniuch Level 1

                    Well, a startup jsx script attempts to create an engine when Ai starts up.

                    But apprently fails, because the next script run from ESTK cannot access it.

                    I am aware that jsxbin won't do that so I stick with jsx.

                     

                    Moniuch