4 Replies Latest reply on Feb 16, 2015 2:10 PM by Melchiar

    Copy layer contents to other opened docs - crashing inDesign


      Hi everyone,


      As part of my work flow, I've written a script that's meant to copy to contents of a particular layer (in this case "palette") from whatever document you currently have active, over to any other opened documents that begin with the same name (ie. "order 2341 - large" would copy and replace the contents of the palette layer in "order 2341 - small, but the script would ignore any documents that don't begin with "order 2341").


      The problem is that the pasteInPlace(); component of my script is crashing inDesign (I'm running CS 5.5). Strangely enough, if I stop the script before this point and paste the contents in manually it works just fine, so it seems it's only the scripted component that has the issue. Would anyone be able to take a look and see if there's something I'm doing wrong, or if this is just a strange ID bug?


      //script to copy contents of a specific layer over to all other opened documents that begin with the same name
      //written by Steve Eberhardt
      var myDocument = app.activeDocument;
      var docName = myDocument.name.match(/[^-]+/);
      var paletteLayer = null;
      var count = 0;
      paletteLayer = app.activeDocument.layers.itemByName("palette");
      var paletteObjects = app.activeDocument.layers.itemByName("palette").allPageItems;
      var docs = new Array();
      for (var i = app.documents.length - 1; i >= 0; i--) {
      for (var i = 0; i < docs.length; i++) {
          app.activeDocument = app.documents.itemByName(docs[i]);
          var otherDoc = app.activeDocument.name.match(/[^-]+/);
          if (docName.toSource() == otherDoc.toSource() && app.activeDocument != myDocument) {
              paletteLayer = app.activeDocument.layers.itemByName("palette");
              try {
                  var paletteGroup = new Array;
                  paletteGroup = app.selection;
              } catch (_) {}
              app.pasteInPlace();//this action crashes indesign
      app.activeDocument = myDocument;
      alert("Copied " + myDocument.name.replace(/.indd$/, '') + " palette to " + count + " documents");