2 Replies Latest reply on Apr 17, 2013 1:19 PM by Jessemac3992

    Passing a variable from Photoshop to Illustrator

    Jessemac3992

      Alright, so I've been on here a lot the last couple weeks trying to figure out BridgeTalk, and I am starting to get the hang of it.  I am writing an Illustrator script which will open a specified template and then grab Photoshop's active document and place it on the template.  I have everything working perfectly with one hiccup.  The script goes to Photoshop, grabs the filepath, opens the Illustrator doc, and places the file perfectly.  BUT it always takes two runs through the script for it to work.  It's the weirdest thing.  So if I run the script when PS first opens, it gives me an error; if I run it again it works perfectly, but if I close that PS doc and open a new one, then run the script, it places the previous document! 

       

      I am stumped and have tried everything I can think of.  Here is a simplified version of the part of the script that produces the error.  The first time I run the script, "alert(psFile)" is completely wrong, but when I run it again it works perfectly. 

       

       

       

      #target illustrator
      
      
      var psFile;
      
      
      infoFromPS ();
      
      
      var illTemp = File("/Users/art1/Desktop/template.ai");
          app.open(illTemp);
      
      var doc = app.activeDocument;
      
      
      
      
      function infoFromPS() {
         var bt = new BridgeTalk;
         bt.target = "photoshop";
         bt.body = "app.activeDocument.fullName;"
         bt.onResult = function(resObj) {
            var myResult = resObj.body;
            psFile = File(myResult);
      }
         bt.send();
      }
      
      
      alert(psFile);
      
      
      
      
      
        • 1. Re: Passing a variable from Photoshop to Illustrator
          CarlosCanto Adobe Community Professional & MVP

          this simplified version is so simplified that is not connecting illustrator with photoshop in any way to be able to tell...but in any case, your script is not waiting for the result, it keeps going after you send it, that's why you get an error the first time, then after you get the previous result

           

          it goes like this the first time

           

          var psFile; // undefined
          infoFromPS (); // I'm not waiting for bridgeTalk to fetch me the result
          
          alert(psFile); // psFile is undefined,
          //...bridgeTalk returns the result after you're done
          psFile = 'some file';
          

           

          second time, or after you change the ps activeDocument

           

          var psFile; // I still have in memory the result from previous run ('some file')
          infoFromPS (); // I'm still not waiting for the result
          
          alert(psFile); // psFile is 'some file' from previous run,
          //...bridgeTalk returns the result after you're done
          psFile = 'some other file';
          
          1 person found this helpful
          • 2. Re: Passing a variable from Photoshop to Illustrator
            Jessemac3992 Level 1

            Yeah this is exactly what I was assuming was happening.  Any suggestions for forcing an order of events to get the return of the BridgeTalk before the rest of the script runs?  Is there a way to trigger the rest of the script on the completion of the BridgeTalk?