14 Replies Latest reply on Sep 22, 2014 5:20 AM by newtoindesign

    [JS CS6] paste onto active document from external .indd

    newtoindesign Level 1

      Hey everyone, i'm at a complete loss with this, tried loads of examples from this forum etc and cant get anywhere so i've given up!

       

      All i'm trying to acheive is to prompt the user for a code, then that refrences an indesign file in a folder, this is all working ok, we have a variable called BMDFile with a full file path ready to go, but I can't figure out how to get this file on a currently open document in an editable format.

       

      I just want it to paste from an indesign file onto this empty doc

       

      I'm trying to edit this example from the forum now...

       

      var doc1 = app.documents[1]; //  needs to be from an external .indd file (variable BMDFile already contains a full path)

      var doc2 = app.documents[0];  // paste to

       

      for(i=0; i<doc1.pages.length; i++)

      {

          if(doc2.pages.length < i+1){

              doc2.pages.add();

          }

          doc1.pages[i].pageItems.everyItem().duplicate(doc2.pages[i]);

      }

       

      Thanks in advance!

        • 1. Re: [JS CS6] paste onto active document from external .indd
          TᴀW Adobe Community Professional & MVP

          Have you looked into placing the file?

           

          Document.place (fileName:varies, showingOptions: Boolean ,

          withProperties: Object )

          Adobe InDesign CC (64 bit) (8.0) Object Model

          Place one or more files following the behavior of the place menu item.

          This may load the place gun or replace the selected object, depending on

          current preferences.

          fileName: Data Type: varies

          One or more files to place. Can accept: File or Array of Files.

          showingOptions (optional): Data Type: Boolean , Default Value: false

          Whether to display the import options dialog (Optional)

          withProperties: Data Type: Object

          Initial values for properties of the placed object(s) (Optional)

          • 2. Re: [JS CS6] paste onto active document from external .indd
            newtoindesign Level 1

            Unfortunately what I'm pasting needs to be editable (they're templates for various differently designed text boxes, some with graphics, backgrounds, headings etc), when I place an .indd file it just becomes a static graphic (unless I paste snippets, but they're not as quick to edit as an .indd)

            • 3. Re: [JS CS6] paste onto active document from external .indd
              TᴀW Adobe Community Professional & MVP

              That's the way it works when you place InDesign files. Scripting can't

              change that.

               

              If you were to do this manually with the UI, what steps would you take

              to achieve what you want? Those steps can be scripted. But if you can't

              do it manually in the UI, you probably can't automate it via scripting.

              • 4. Re: [JS CS6] paste onto active document from external .indd
                newtoindesign Level 1

                The method would be, assuming the blank document is already open:

                 

                • Open the appropriate BMDFile .indd
                • Copy all from it
                • Paste to the already open blank document (which will be the correct size, they're all the same)
                • Close the external file
                • 5. Re: [JS CS6] paste onto active document from external .indd
                  mdegamo Level 1

                  If I would to implement this, I would prefer to make the BMDFile an InDesign template, when the user executes the script it will open BMDFile and fire up the Save As dialog immediately. The BMDFile will not be overwritten because it will be opened as a new untitled document with all the settings in place. Please refer to script below.

                   

                  #target "indesign";
                  #strict "true";
                  
                  
                  (function () {
                      var BMDFile = File('/the/path/of/BMDFile.indt');
                  
                  
                      if (BMDFile.exists) {
                          app.open(BMDFile, true, OpenOptions.OPEN_COPY);
                      } else {
                          alert('Template file not found. Create a new document instead',
                                'File not found error',
                                true);
                      }
                  }());
                  
                  • 6. Re: [JS CS6] paste onto active document from external .indd
                    newtoindesign Level 1

                    Unfortuately the Workflow setup here (that I cant change is)

                     

                    • Designer accepts a job for a customers ad with other software we use, it creates a blank indesign template with the correct name in the correct place with correct colour settings etc
                    • It opens that blank document in InDesign and the designer makes the ad
                    • Designer ends the job by using a script here (which I cant change) to Save (on top) & generate a PDF to specific settings

                     

                    So unfortunately the 'current empty document' I'm looking to paste this external stuff onto, is a file that could be in various different folders and names, i can't see an easy way to script it.

                     

                    I just wanted to script:

                     

                    • Designer has the automatic blank template up, sees its a repetative ad
                    • Designer presses F4 (or similar for this script) types a code number
                    • Script pastes the almost fully made ad on the template for them

                     

                    If indesign cant do this, i'm probably better off scripting windows to find out where these files are saves and copy a pre-saved template into the relevant folder with the new name (if i can find out how its generated) and then open that.  But this means the designer would be shutting down a blank template, running a script then opening it, not very intuative.  I was thinking of a library but only one user can work on it at a time, so not ideal.  Placing a Snippet DOES work, leaving editable objects, but to update a snippet seems to be a lot of unnecessary clicks if it could just remain an .indd that anyone could go in and update as necessary

                     

                    Before you think it, don't worry, i agree this companies workflow is akward at best, i'm just trying to save daily repetitive clicks, file browsing and copy & pasting for pretty simple templates.

                    • 7. Re: [JS CS6] paste onto active document from external .indd
                      Jump_Over Level 5

                      Hi,

                       

                      Did you check your index refers to a proper file?

                      Order of opening matter so the last opened index is 0.

                       

                      Jarek

                      • 8. Re: Re: [JS CS6] paste onto active document from external .indd
                        newtoindesign Level 1

                        Ah thankyou Jarek, I was wrong on the indexes!  I thought last opened was [1]

                         

                        This ALMOST works

                         

                        app.open(BMDFile);

                        var doc1 = app.documents[0]; // copy from

                        var doc2 = app.documents[1];  // paste to

                        for(i=0; i<doc1.pages.length; i++)

                        {

                            if(doc2.pages.length < i+1){

                                doc2.pages.add();

                            }

                            doc1.pages[i].pageItems.everyItem().duplicate(doc2.pages[i]);

                        };

                        app.activeDocument.close();

                         

                        But there are items missing from the copy & paste, it doesn't seem to bring across any images boxes?

                        • 9. Re: [JS CS6] paste onto active document from external .indd
                          Jump_Over Level 5

                          Hi,

                          check these items location. It takes the items which parent is page[i].

                          If any item location is outside of page (pasteboard) - its parent is a spread.

                           

                          Maybe duplicating spreads[i].pageItems is a better solution?

                           

                          Jarek

                          • 10. Re: [JS CS6] paste onto active document from external .indd
                            newtoindesign Level 1

                            ah apologies, it is pasting the graphics, but the layer order is changing during the paste so they were all behind.  I guess i need to script it to group everything before pasting or something?

                            • 11. Re: [JS CS6] paste onto active document from external .indd
                              Jump_Over Level 5

                              Hi,

                              You will not able to group items across different layers.

                              Try to manage layers proper order (using layer.move() method).

                               

                              Jarek

                              • 12. Re: [JS CS6] paste onto active document from external .indd
                                newtoindesign Level 1

                                Hmm, everything on the source document(s) only have 1 layer, the script seems to be re-ordering the items back to front, so the white background is becoming the topmost item after the duplicate

                                • 13. Re: [JS CS6] paste onto active document from external .indd
                                  Jump_Over Level 5

                                  Hi,

                                   

                                  Right.

                                  Looping bacward should fix it

                                   

                                  for(i = doc1.pages.length-1; i >= 0; i--)

                                   

                                  Jarek

                                  • 14. Re: [JS CS6] paste onto active document from external .indd
                                    newtoindesign Level 1

                                    Seems to give the same result I'm afraid, images are behind still.

                                    Managed to cobble together a group/ungroup method which seems to work!

                                     

                                     

                                     

                                    // open the BMDFile external doc

                                    app.open(BMDFile);

                                     

                                    var doc1 = app.documents[0]; //  the BMDFile external doc

                                    var doc2 = app.documents[1];  // currently open blank doc

                                     

                                    for(i=0; i<doc1.pages.length; i++)

                                    {

                                        if(doc2.pages.length < i+1){

                                            doc2.pages.add();

                                        }

                                     

                                    // group everything to avoid the order changing

                                        var myObj = new Array;

                                        myObj = app.activeWindow.activePage.pageItems;

                                        app.activeWindow.activePage.groups.add(myObj);

                                     

                                    // duplicate

                                        doc1.pages[i].pageItems.everyItem().duplicate(doc2.pages[i]);

                                       

                                    // ungroup everything

                                        with(app.documents[1]) { 

                                            while (groups.length != 0) { 

                                            groups.everyItem().ungroup(); 

                                            } 

                                          }      

                                     

                                    };

                                     

                                    // close the BMDFile external doc, dont save changes

                                    app.activeDocument.close(SaveOptions.no);

                                     

                                     

                                     

                                    It's probably not ideal, but my company aren't paying me to do this, so it will do for now!