2 Replies Latest reply on Oct 10, 2016 4:27 AM by lucas.maximus

    Copy from Doc1 and paste in Doc2 - in center of page

    lucas.maximus

      Hello to everyone on the forums,

       

      I am using the code below to open 'doc1' and paste its contents into 'doc2'

       

      Could anyone please help me to ensure doc1 is pasted into the center of doc2?

      doc2 is larger, and the objects currently paste off center, flush to the left hand side and centrally on the y-axis

       

      If there is a way to paste directly to center? or if not, move everything to the center after pasting?

       

      Thank you!

      ------------------------------------------------

       

       

      // open the BMDFile external doc

      var BMDFile = "myfilepath"

      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);