8 Replies Latest reply on Feb 12, 2013 9:17 AM by klemango

    BridgeTalk Messages Inside onClick Function

    klemango Level 1


      Is there any reason why I can't have 2 separate BT messages inside one onClick function call?  I have two BT messages, one for IA and one for Photoshop, but only one will complete.  If I either have one or the other, they work, but not both.  Do I have to prepare them in a specific way?



        • 1. Re: BridgeTalk Messages Inside onClick Function
          CarlosCanto Adobe Community Professional & MVP

          this is one way to do it...


          btnOk.onClick = function(){
              aiscript ();
              psscript ();


          function aiscript() {
              var bt = new BridgeTalk;
              bt.target = "illustrator";
              var myScript = "var idoc = app.documents.add();"
              myScript += "var ipath = idoc.pathItems.rectangle(100, 200, 100, 200);"
              bt.body = myScript;
          function psscript() {
              var artWidth = 800;
              var artHeight = 600;
              var bt = new BridgeTalk;
              bt.target = "photoshop";         
              var script = "app.preferences.rulerUnits = Units.PIXELS; app.documents.add(" + artWidth + "," + artHeight + ");"       
              bt.body = script;
          • 2. Re: BridgeTalk Messages Inside onClick Function
            klemango Level 1

            Thanks again for your help, Carlos.  It seems I was having other issues, too.  Namely, my script was "running over" itself.  I have 3 functions... The first saves an open AI document as an EPS, the next opens it in Photoshop and immediately saves it as a TIFF file with certain settings the file requires, then the TIFF is reopened in AI again for further processing.  My script was trying to open the TIFF file before it was finished saving from Photoshop (got that fixed).  All of this would be a mute point if  I could just export the file directly from AI with the settings I need.  I've read somewhere in the forums that CS6 has improved support for TIFF files in AI, is that true?

            • 3. Re: BridgeTalk Messages Inside onClick Function
              klemango Level 1

              Another question...


              Does it matter if the functions are inside or outside the w.show(); statement?

              • 4. Re: BridgeTalk Messages Inside onClick Function
                Muppet Mark Level 5

                If you are using CS6 then yes there are new antiAliasing options… To stop your script running away with itself you put the start in AI call out to PS with bridgetalk… continue the rest of AI from the onResult() call back…

                • 5. Re: BridgeTalk Messages Inside onClick Function
                  klemango Level 1

                  I think I understand what you're saying... By using the onResult(), that will force the script to wait until Photoshop has finished and returned a message?


                  But, my original problem still exists:  Only one of these  calls in the onClick function will work when both are available.  If you remove one or the other, they will work, but not both together:


                  #target illustrator

                  #targetengine main



                  var w = new Window("palette","VPG Scripting",undefined,{closeButton:true});  

                      var btnOk = w.add ("button", undefined, "OK");

                      var btnCanel = w.add ("button", undefined, "Cancel");



                  btnOk.onClick = function(){








                  function saveEPS()


                      var bt = new BridgeTalk();

                      bt.target = "illustrator";


                      var script =  "var destination = (\"S:/Extras/Bookmark.eps\");" +

                      "exportFileToEPS(destination);" +

                      "function exportFileToEPS(destFile){" +

                      "copy();"  +

                      "var delSel = app.activeDocument.selection;" +  

                      "for (i=0;i<delSel.length;i++){" +

                      "delSel[i].remove();" +

                      "}" +

                        "app.documents.add();" + 

                      "var saveDoc = app.activeDocument;" +

                      "paste();"  +   

                      "var newFile = new File(destFile);" +

                      "var saveDoc;"  + 

                      "if ( app.documents.length == 0 ){" +

                      "saveDoc = app.documents.add();}" +

                      "else {saveDoc = app.activeDocument;}" +

                      "var saveOpts = new EPSSaveOptions();" +

                      "saveOpts.cmykPostScript = true;" +

                      "saveOpts.embedAllFonts = true;" +

                      "saveDoc.saveAs( newFile, saveOpts );" +



                      bt.body = script;





                  function photoshopFile()


                     var bt = new BridgeTalk();

                          bt.target = "photoshop";


                           var script = "var originalRulerUnits = app.preferences.rulerUnits;" +

                              "app.preferences.rulerUnits = Units.PIXELS;" +

                              "var fileRef = new File(\"S:/Extras/Bookmark.eps\");" +


                              "var pdfOpenOptions = new EPSOpenOptions;" +

                              "pdfOpenOptions.antiAlias = true;" +

                              "pdfOpenOptions.mode = OpenDocumentMode.CMYK;" +

                              "pdfOpenOptions.resolution = 300;" +

                              "pdfOpenOptions.page = 3;" +

                              "app.open( fileRef, pdfOpenOptions );" +


                              "app.preferences.rulerUnits = originalRulerUnits;" +

                              "var saveName = new File (\"S:/Extras/Bookmark\");" +

                              "saveOpts = new TiffSaveOptions();" +

                              "saveOpts.imageCompression = TIFFEncoding.JPEG;" +

                              "saveOpts.jpegQuality = 12;" +

                              " saveOpts.layers = true;" +

                              "saveOpts.embedICCProfile = true;" +

                              "app.activeDocument.saveAs( saveName, saveOpts );" +

                              "fileRef.remove();" +



                          bt.body = script;





                  • 6. Re: BridgeTalk Messages Inside onClick Function
                    Michael L Hale Level 5

                    If you don't include a timeout in the send the onClick function will not wait and send the second message right away. In effect of telling Photoshop to open an file that doesn't yet exists. You can run them one at a time because only if you have already created the edited copy( or at least you use one that exists ).


                    Without using onResult and onError the script doesn't know that Illustrator isn't done or the reason the Photoshop message failed.


                    The reason Carlos' example works is the two messages are independent and don't count on the first being done before the second starts.

                    • 7. Re: BridgeTalk Messages Inside onClick Function
                      klemango Level 1

                      Awesome, that makes perfect sense.  I was assuming (incorrectly) that this was all being buffered and the script would wait until one action was complete before starting the next. I didn't stop to think that there are two programs (AI and PS) getting separate commands, one right after the other and that they would be executed immediately. 


                      Now, is it possible to call the PS function from the onResult return?  I still need to allow ample time for the file to actually SAVE to the disk, too.  Maybe an "if file exists?" statement to make sure it's there first?


                      Thanks for that explanation, Michael.  Up until now, I haven't had a need for the other options in BridgeTalk, but now I do, so it's time to get busy learning.

                      • 8. Re: BridgeTalk Messages Inside onClick Function
                        klemango Level 1

                        Works perfectly:


                        bt.onResult = function(retObj){photoshopFile()};


                        Thanks again everyone!!!