4 Replies Latest reply: May 23, 2014 11:05 AM by Trevor_Meiss RSS

    Calling one script from another

    frameexpert Community Member

      InDesign has a nice mechanism for calling one script from another, so code can be made modular. What about FrameMaker ExtendScript? What methods are people using to call one script from another? Thanks for any suggestions.

       

      Rick Quatro

        • 1. Re: Calling one script from another
          4everJang Community Member

          Hi Rick,

           

          I write my scripts such that they always have the entire code in a function call, Basically, the only piece of code outside the main function call is calling that main function (so that I can test and debug each script separately). Then, when I use #include <scriptname.jsx> I can use that same script from another one. Normally, I write one overall script that installs the various commands in menus and contains the switch for the command function that calls each of the separate scripts, all of which are included via the #include. Save that overall script as binary and you do not need to drag all the scripts into the startup directory.

           

          Kind regards from c-c-c-c-cold Netherlands

           

          Jang

          • 2. Re: Calling one script from another
            Trevor_Meiss Community Member

            Hi Jang,

             

            Can you further explain:

            Save that overall script as binary and you do not need to drag all the scripts into the startup directory.

            When I use #include <scriptname.jsx>, I get the following error:

             

            Script Error :

            Error Message      : File or folder does not exist

            Script, Line#   : C:\path\to\script\overall_script.jsx,  1

             

            This happens even when the two scripts are in the same folder.

             

            Thanks in advance,

            Trevor

            • 3. Re: Calling one script from another
              4everJang Community Member

              Hi Trevor,

               

              Note that ExtendScript is Javascript plus FM objects and methods, so you need to stick to Javascript syntax rules. The right way to include another script source is as follows:

               

              #include "scriptname.jsx";

               

              If this works when running the main script from the ESTK, you know it finds the included script. When you then Export the script to Binary (from the File menu of the ESTK), the binary will include the embedded script as well. After this you have a jsxbin file, which you can drop into one of the two available startup folders to make it fire automatically when FM starts. Or you can move it anywhere else and run it via the File > Script > Run command. The main idea here is that when compiling a script into binary format, all include references are resolved and the script contains the complete code. If you run the jsx, the script is interpreted and requires a correct relative reference to any included script.

               

              I hope this clarifies things a little

               

              Ciao

               

              Jang

              • 4. Re: Calling one script from another
                Trevor_Meiss Community Member

                Thanks for all your help! One last question, is it possible to include a script from a network server?

                 

                For example, something like

                #include "\\network_server\path\to\scriptname.jsx";

                 

                Edit:

                Just to be clear, what I would like to be able to do is modify the scripts called by overall_script.jsx without having to remake the binary file every time.