4 Replies Latest reply on Dec 10, 2013 3:38 AM by Beliakov

    why bridgetalk doesn't work in cycle?

    Beliakov Level 1

      i save three layers (from forst to third) to EPS and than open it in AI and resave as older EPS version (and some cleaning procedures).

       

      ////////////main cycle through layers
      for (ml=0; ml<mlayersName.length; ml++) {
      mLayers(mlayersName[ml]);
      }
      //////////////////////////////////////////////////////////////////
      
      
      function mLayers(mName)
      {
      for(L = 0; L < mDoc.layers.length; L++){  /////////cycle for no visibility for all other layers
        if(mDoc.layers.item(L).name == mName){mDoc.layers.item(L).visible = true;}
        else{mDoc.layers.item(L).visible = false;} 
        }
      
      
          toEPS(mName);
          /// open in AI
          mFnameEPSIllu = mFname.split(".")[0]+"_" + mName + ".eps";
          var myFileIllu = File(mPath + mFnameEPSIllu);
      
                 var myArgumentsAsArray = [myFileIllu];                  
                                mscript = myIlluScript;
      
                          mscript += '\myIlluScript(' + myArgumentsAsArray.toSource()+ ');';
                          btMessaging( 'illustrator', mscript );
      }  //function mLayers(mName) END
      
      
      //////////////////saving in EPS from InDesign
      function toEPS(mName) {
      
      mFnameEPS = mFname.split(".")[0]+"_" + mName + ".eps";
      var myFile = File(mPath + mFnameEPS);
      
      if (mName.match("face") !=null){
          app.epsExportPreferences.pageRange = '3';
          }else if (mName.match("back") !=null){
              app.epsExportPreferences.pageRange = '1';
              }else{
                  app.epsExportPreferences.pageRange = '2';
                  }
      mDoc.exportFile(ExportFormat.epsType, myFile, false);
      }
      //////////////////
      
      
      
      function btMessaging( targetApp, mscript ) {
                var bt = new BridgeTalk();
                bt.target = targetApp;
                bt.body = mscript;
                bt.send(); 
      BridgeTalk.bringToFront( 'illustrator' );
      }
      
      
      ////script string for AI ///resaving in EPS from AI
      
      
      function myIlluScript(aArray){
      app.open(aArray[0]);
      app.executeMenuCommand('selectall');
      app.executeMenuCommand('Fit Artboard to selected Art');
      var saveOptions = new EPSSaveOptions();
      saveOptions.compatibility = Compatibility.ILLUSTRATOR8;
      var saveName = new File (aArray[0]);
      $.writeln('file in AIscript: ' + aArray[0]); ////// !!!!!!!!!! this line appears only one time instead of tree!!!!!!!!!!!!!
          var docRef = activeDocument;
      docRef.saveAs(saveName, saveOptions);
      docRef.close();
         docRef = null;
          }
      
      

      But AI script appears to work only once - very first iteration.

      Why does this happens?

        • 1. Re: why bridgetalk doesn't work in cycle?
          pixxxel schubser Level 5

          Too many variables are not defined. The snippet is not executable standalone.

           

          A guess: There is a "backslash-bug" between Bridge Talk and Illustrator. Maybe that's the cause.

          Or because of you do: app.open(aArray[0]); instead of loop through the aArray.

          Without seeing what the script does it is only a „look into the crystal ball“.

           

          Sorry.

          • 2. Re: why bridgetalk doesn't work in cycle?
            Laubender Adobe Community Professional & MVP

            @pixxxel schubser – This "backslash-bug" is not only between BridgeTalk and Illustrator.

            It's a bug (?) with BridgeTalk. Independent of the app you talk to…

            @Demitry – Instead of using // to comment out your code, use always /*…*/ for comments when working with BridgeTalk.

             

            Uwe

            • 3. Re: why bridgetalk doesn't work in cycle?
              pixxxel schubser Level 5

              Hallo Uwe,

              ich hatte es zwar befürchtet, wollte aber trotzdem vorsichtig optimistisch bleiben.

               

              • 4. Re: why bridgetalk doesn't work in cycle?
                Beliakov Level 1

                interesting, that analog (this simplyfied) script do work properly.

                 

                #target indesign

                var mDoc = app.activeDocument;

                fullDocName = mDoc.fullName;

                mPath = "/Users/somebody/Documents/tmp/";

                mFname = mDoc.name.toString();

                 

                mlayersName = ['Layer 1', 'Layer 2', 'Layer 3'];

                 

                for (is = mDoc.stories.length-1; is>=0; is--){

                    $.writeln(is);

                    try {mDoc.stories[is].createOutlines();}

                    catch (myError){};

                }

                 

                ////////////////////////////////// - main cycle - ////////////////////////////////////////////

                //выгонка EPS'ов по слоям

                for (ml=0; ml<mlayersName.length; ml++) {

                mLayers(mlayersName[ml]);

                }

                ////////////////////////////////////////////////////////////////////////////////////////// //////

                 

                function mLayers(mName) /* highlight the target layer */

                {

                for(L = 0; L < mDoc.layers.length; L++){

                                              if(mDoc.layers.item(L).name == mName){mDoc.layers.item(L).visible = true;}

                                              else{mDoc.layers.item(L).visible = false;}

                }

                toEPS(mName);

                 

                /* prepare modification name for EPS */

                    mFnameEPSIllu = mFname.split(".")[0]+"_" + mName + ".eps";

                    var myFileIllu = File(mPath + mFnameEPSIllu);

                 

                           var myArgumentsAsArray = [myFileIllu];                 

                                    mscript = myIlluScript;

                                    mscript += '\myIlluScript(' + myFileIllu.toSource()+ ');';        

                                    btMessaging( 'illustrator', mscript );

                }  ///////

                 

                 

                 

                 

                //////////////////

                function toEPS(mName) { 

                mFnameEPS = mFname.split(".")[0]+"_" + mName + ".eps";

                var myFile = File(mPath + mFnameEPS);

                app.epsExportPreferences.pageRange = '1';

                mDoc.exportFile(ExportFormat.epsType, myFile, false);

                }

                //////////////////

                 

                 

                function btMessaging( targetApp, mscript ) {

                          var bt = new BridgeTalk();

                          bt.target = targetApp;

                          bt.body = mscript;

                          bt.send();

                BridgeTalk.bringToFront( 'illustrator' );

                }

                 

                 

                function myIlluScript(mEPS){

                app.open(mEPS);

                /* just for test of workin this subscript*/

                    }

                alert("Done!");

                 

                after testing previous version, in AI i see only first opened file. That means, that strings of AI-script fulfils only once (in version of topicstarter).