10 Replies Latest reply on Jun 17, 2011 8:35 AM by Kasyan Servetsky

    Cross Program doscript without BridgeTalk??

    divinewind

      If I have a script that isn't really doing anything in Indesign or Illustrator but rather folder and file management and reads an xml file to populate a bunch of variables, is it possible to call a script (using doScript();) that targets Indesign or Illustrator and pass the variables from the main script to it, or does this need to be done using BridgeTalk only?

       

      Just a little rundown,

       

      I have a script that asks the user for a job number, it then proceeds to find a corresponding xml file with all the job information, creates the folders necessary and copies the proper illustrator files it needs into that created folder.  I then want to call an illustrator script that we have, open the illustrator file, strip away layers it doesnt need by comparing its contents with the xml file data, and resave it. Then open an indesign file, relink all the images with this new illustrator file and populate a bunch of tags/variables with the xml file data and export PDF's.

       

      Right now I have all these three steps in seperate scripts that we run manually each step of the way down the job line,  but would like to have it all go through automatically using one main script.

       

      Is it possible with doscripts() or is BridgeTalk inevitable?

        • 1. Re: Cross Program doscript without BridgeTalk??
          Kasyan Servetsky Level 5

          If your scripts are written in JS, BridgeTalk is the best option for you since it is designed for comunication between Adobe applications.

          Another option is to translate your scripts to AS or VB, in this case you can address all applications directly. doScript is used for running a script written in another language from InDesign and is very useful to overcome some limitations of JS. For example, the main part of a script written in JS may process the links in the active document: via BridgeTalk run a Photoshop script which opens, resizes, sharpens, ... etc, saves, closes each image. Then it updates all the links and exports the document to pdf-file. Finally the script sends the pdf-file by e-mail from 'Mail' application which can't be implemented in JS so this part is written in AS and triggered by doScript from the 'main' script.

          BridgeTalk is not as scary as it seems at first. Here on the forum, you can find many examples of interacting InDesign with Photoshop, Bridge, Illustrator and even Acrobat.

           

          Hope this helps.

           

          Kas

          • 2. Re: Cross Program doscript without BridgeTalk??
            John Hawkinson Level 5

            Indeed, why do you wish to avoid BridgeTalk?

            It might be advantageous to have your BridgeTalk messages be short simple app.doScript() messages, to avoid quoting bugs in Bridgetalk.

            1 person found this helpful
            • 3. Re: Cross Program doscript without BridgeTalk??
              divinewind Level 1

              Yeah I know, I was just being that way because I have looked up as much on this forums as I can about Bridgetalk and I just can't seem to get my head around it.  I understand JS enough to do what I need to do, but then I look at the coding for Bridgetalk and I just dont understand why it looks so different.  But anyhow,  with that said. I'll keep looking.  We are only using Illustrator and Indesign for what we do in the office, so it can't be all that hard.

               

              The app.doScript() in bridgetalk may be my solution, thanks guys.

               

              One question I do have though is..   If I have all the variables set in the main script, and pass the variable data populated by xml to Illustrator using Bridgetalk, start the script for Illustrator for each job using the app.doScript() : as stated, the main question I have is, Will the script wait for the script in Illustrator to finish and send a reply back via Bridgetalk before sending another bridgetalk message to Indesign to update the files with the newly made illustrator files and export PDF's or do you have to program the wait with listeners or the like??

               

              Also, I'm also totally oblivious as to how to return variables BACK to the main script from say Illustrator and then to indesign, any incite would be helpful as I'm generally pretty good at picking apart coding and altering it for my own use.

               

              Thanks in advance!

               

              PS.  an example of what I am looking for would be...

               

              Variables are populated and bridgetalk is used to find/open and strip away layers from the proper illustrator template, and then resave it with a new file name (this is already scripted) This file name variable is then sent back to the main script and passed to indesign (this is the step I don't know how to do)  for another script that relinks and generates PDFs (this is already scripted as well)

               

              Just a basic example of something simple and similar would be awesome.

              • 4. Re: Cross Program doscript without BridgeTalk??
                Kasyan Servetsky Level 5

                Yes, you can make the InDesign script to wait untill the Illustrator script (Sent via BridgeTalk) finishes -- you have to do two things for this:

                Define an onResult function -- it can be just empty function and set some value for the timeoutInSecs parameter.

                bt.onResult = function(resObj) {} 
                bt.send(30);
                

                 

                An yes, you can get a result from  the Illustrator scrip. BTW, some time ago I posted an example involving InDesign, Illustrator and XML called something like Update Graphs from ID in Illustrator, but I can't find it any more -- the forum's software works terribly for me . If you want, I can repost it with some sample files.

                 

                I can also give you an example of a BridgeTalk script returning the result.

                 

                Kas

                • 5. Re: Cross Program doscript without BridgeTalk??
                  divinewind Level 1

                  Kasyan, you are a god!

                   

                  That would help immensely, as I am pulling my hair out to understand it. I think my biggest problem is all the talk about backslashes and the problems they cause.  Being new to JS for adobe it's just creating more confusion for me and just a basic simple example of passing variables back and forth and waiting for replys from each script is basically all I need to do what I need

                   

                  Anything you have would be more than helpful!!

                  • 6. Re: Cross Program doscript without BridgeTalk??
                    Kasyan Servetsky Level 5

                    Yeah, the adobe's documentation, as far as BridgeTalk concerns, is very confusing and when I explored it (it was CS2 version) there were a lot of typos and mistakes.

                    Here is the script:

                    #target indesign
                    
                    var myXmlPath = "/c/Test/Capella Gross Sector Exposure.xml";
                    var mySetName = "Capella";
                    
                    var myDoc = app.activeDocument;
                    ProcessLinks();
                    UpdateLinks()
                    alert("Done");
                    
                    // ------------------------- FUNCTIONS -------------------------
                    function ProcessLinks() {
                         for (var j = 0; j < myDoc.links.length; j++) {
                              var myLink = myDoc.links[j];
                              CreateBridgeTalkMessage(myLink.filePath, myXmlPath, mySetName);
                         }
                    }
                    
                    function CreateBridgeTalkMessage(myAiPath, myXmlPath, mySetName) {
                         var bt = new BridgeTalk();
                         bt.target = "illustrator";
                         var myScript = UpdateDataset.toString() + '\r';
                         myScript += 'UpdateDataset(\"' + myAiPath + '\", \"' + myXmlPath + '\", \"' + mySetName + '\");';
                         bt.body = myScript;
                         bt.onResult = function(resObj) {} 
                         bt.send(30);
                    }
                    
                    function UpdateDataset(myAiPath, myXmlPath, mySetName) {
                         var myAiFile = new File(myAiPath);
                         var myDoc = app.open(myAiFile);
                         var myXmlFile = new File(myXmlPath);
                         if (myXmlFile.exists) {
                              myDoc.importVariables(myXmlFile);
                              myDoc.activeDataset = myDoc.dataSets.getByName(mySetName);
                              myDoc.activeDataset.display();
                              myDoc.close(SaveOptions.SAVECHANGES);
                         }
                    }
                    
                    function UpdateLinks() {
                         for (var i = myDoc.links.length-1; i >= 0; i--) {
                              if (myDoc.links[i].status == LinkStatus.linkOutOfDate) {
                                   myDoc.links[i].update();
                              }
                         }
                    }
                    

                     

                    And here is a zip-file with samples.(CS3)

                    1 person found this helpful
                    • 7. Re: Cross Program doscript without BridgeTalk??
                      divinewind Level 1

                      Thank you..

                       

                      that example makes it all so clear to me and I've learned more about Bridgetalk with that example then I have in weeks of scouring the documentation and forums.

                       

                      By looking at this I can see that I can have all the functions that I have in separate scripts at the moment in one main script and then pass the functions and parameters (variables) to each program using bridgetalk, so there is no need for the variables to be in the separate illustrator script.

                       

                      The whole ('\") is where I get confused and don't fully understand why it's there.  But I should be able to figure it out for what I need.

                       

                      Much Thanks!!!

                      • 8. Re: Cross Program doscript without BridgeTalk??
                        Kasyan Servetsky Level 5

                        The whole ('\") is where I get confused and don't fully understand why it's there.  But I should be able to figure it out for what I need.

                        I escape quotes so that to pass arguments from InDesign to the Illusrator script.

                        • 9. Re: Cross Program doscript without BridgeTalk??
                          John Hawkinson Level 5

                          I agree that unnecessary escaping is confusing:

                           


                          function CreateBridgeTalkMessage(myAiPath, myXmlPath, mySetName) {
                               var bt = new BridgeTalk();
                               bt.target = "illustrator";
                               var myScript = UpdateDataset.toString() + '\r';
                               myScript += 'UpdateDataset(\"' + myAiPath + '\", \"' +
                                   myXmlPath + '\", \"' + mySetName + '\");';      bt.body = myScript;

                          As I said when we last discussed this, post #31 of Re: Bridge talk for InDesign CS4/CS5 js, it would be much easier to just write:

                           

                          function CreateBridgeTalkMessagE(myAiPAth, my XmlPath, mySetName) {
                            var bt = new BridgeTalk();
                            bt.target = "illustrator";
                            bt.body = UpdateDataSet.toSource+"("+
                              myAiPath.toSource()+","+
                              myXmlPath.toSource()+","+
                              mySetName.toSource()+")";
                          

                           

                          No goofy quoting.

                          • 10. Re: Cross Program doscript without BridgeTalk??
                            Kasyan Servetsky Level 5

                            Hi John,

                             

                            I remember this discussion, but I wrote this example long before it. Yesterday I was too busy with work so I just took it from my archive and posted it as it was. I agree that your version is better and much more elegant than mine. Thanks for correcting me.

                             

                            Regards,

                            Kasyan