1 Reply Latest reply on Oct 10, 2012 10:58 AM by dvondle

    Copy pasting between Illustrator and InDesign with BridgeTalk?

    dvondle

      So my end-goal is to create an illustrator script that takes a multiple-page Illustrator file, copy-pastes the content into InDesign, and turns all of the objects on a layer called "buttons" into buttons to speed up the process from Illustrator to a DPS (Digital Publishing) ready InDesign File.  I can't place the content conventionally because the place command wraps everything up into a single object which makes it impossible to select just the button area when creating buttons for the DPS.

       

      So my idea was to copy and paste each artboard sequentially onto a page in InDesign.  I ran into an issue that I thought some of you may be able to track down.  In my code I have to rely on the BridgeTalk callbacks (bt.onResult), to signal that the paste happened and that I can use the clipboard again for the next artboard.  However, once the app has run some InDesign code and it goes back to the loop it seems to have lost the reference to app.activeDocument.  I indicated in the code below where the code stops running ($.writeln("cuts out below on second iteration")) and have confirmed it only stops when there is a reference to app.activeDocument.

       

      Anyone have some suggestions?  I'm not sure what to try next.

       

      Thanks,

      Dave

       

       

       

      #target illustrator

       

      var sourceDoc = app.activeDocument; // get actual docs

       

      var absCount = sourceDoc.artboards.length;

       

      // get layer visible/lock info & unlock and make visible all layers

      var sourceDocLayerState = unlockUnhideLayers(sourceDoc);

       

      sourceDoc.activate(); // activate source otherwise it is not able to access selection

      createNewInDesign();

       

      var ABs = []; // array to hold of artboard objects to copy

      var ABsRect = []; // array to hold artboards Rectangles

      var ABsNames = []; // array to hold artboard names

      var ABsInfo = []; // array to hold [Rect, Names]

       

      var loopNum=0;

       

      iterateOneLoop(loopNum);

       

      function iterateOneLoop(i) {

          $.writeln("cuts out below on second iteration");

          ABs[i] = sourceDoc.artboards[i]; // get actual artboard

          $.writeln("never reaches here");

          ABsRect[i] = ABs[i].artboardRect; // get Rectangle

          ABsNames[i] = ABs[i].name; // get Name

          ABsInfo[i] = [ABsRect[i], ABsNames[i]]; // get Rectangle and Name

          sourceDoc.selection = null; // deselect everything

          sourceDoc.artboards.setActiveArtboardIndex(i); // activate each artboard

          sourceDoc.selectObjectsOnActiveArtboard(); // select all in artboard

         

          copy(sourceDoc.selection);

          waitForPaste = true;

          addArtboardToInDesign();

      }

       

      function createNewInDesign() {

                // Create the message object

                var bt = new BridgeTalk();

                // Initialize with the target and message string

                bt.target = "indesign";

                bt.body = "var SnpSentMessage = {}; SnpSentMessage.create = " + createInDesignDoc.toString();

                bt.body += "SnpSentMessage.create();"

       

                // Handle error case

                bt.onError = function(errObj)

                {

                          $.writeln(errObj.body);

                }

                // Handler to get the result of the message, so we know when it is completed and with what result

                bt.onResult = function(resObj)

                {

                          // Now we're done, switch the front app to be InDesign to see the result

                          //BridgeTalk.bringToFront("indesign");

                }

                // Send the message

                bt.send();

      }

       

      function addArtboardToInDesign() {

                // Create the message object

                var bt = new BridgeTalk();

                // Initialize with the target and message string

                bt.target = "indesign";

                bt.body = "var SnpSentMessage = {}; SnpSentMessage.create = " + createInDesignPage.toString();

                bt.body += "SnpSentMessage.create();"

       

                // Handle error case

                bt.onError = function(errObj)

                {

                          $.writeln(errObj.body);

                }

       

          bt.onResult = function( retObj ) {

                  if(loopNum< absCount-1){

                      loopNum++;

                      iterateOneLoop(loopNum);

                  }

          }

                bt.send();

      }

       

      function createInDesignDoc() {

          var myDocument = app.documents.add();

          myDocument.documentPreferences.pageHeight = "960 px";

          myDocument.documentPreferences.pageWidth = "640 px";

                return true;

      }

       

      function createInDesignPage() {

                $.writeln("MessageSendingToInDesign: (InDesign) entering createInDesignObjects");

                var mydoc = app.activeDocument;

          //app.pasteInPlace();

          app.paste();

          var mypage = mydoc.pages.add();

         

                return true;

      }