4 Replies Latest reply on Sep 15, 2010 2:07 PM by Larry G. Schneider

    Copy contents of 2 layers to new document with javascript

    MRDV81

      Hi guys !

       

      Basically i have created a new cutfile generator for a Zund cutting machine we have here at work i have got it to the point where i can create a Registration mark layer and Cut layer now i would like to save this as a layered PDF as this is how the cutter software prefers it. What i would like to know is how with Javascript can I copy the contents of "Regmark" layer and "Cut" layer to a dynamically created new document ? Any thoughts on this will be greatly appreciated thanks so much !

       

      Regards,

      Bass

        • 1. Re: Copy contents of 2 layers to new document with javascript
          [Jongware] Most Valuable Participant

          (First thoughts)

           

          * Save As under the new name

          * Delete all but these two layers

           

          This might be the best way, because otherwise:

           

          1. You'd have to create a new document, with all properties of the other one (size, orientation, styles, ...)

          2. You'd have to loop over these two layers and duplicate all items one by one -- 'duplicate' for a layer cannot be used cross-document.

          • 2. Re: Copy contents of 2 layers to new document with javascript
            MRDV81 Level 1

            Thanks you so much for your swift response would it be at all possible to show some syntax for the first option otherwise i have been able to copy one layer successfully over although i lose focus of the "activeDocument" and i can nolonger return to it even if i have a variable to it and i cannot find anywhere in any documentation something that will allow me to return focus to a specific window ! any help once again is greatly appreciated i thank all for their time !

             

            Regards,

            Bass

            • 3. Re: Copy contents of 2 layers to new document with javascript
              MRDV81 Level 1

              Hi guys,

               

              Just something i forgot to add, the follow piece of code copies content of "Regmark" layer to new document but its going back and selecting contents of "Cut" layer i am unable to do thanks once again !

              var sourceDoc = app.activeDocument;
              sourceDoc.select(sourceDoc.layers.item("Regmark").pageItems)
              app.copy();
              var destinationDoc = app.documents.add();
              app.pasteInPlace();
              
              /* NEED SOMETHING HERE TO TAKE ME BACK TO sourceDoc */
              sourceDoc.select(sourceDoc.layers.item("Cut").pageItems)
              app.copy();
              
              /* ONCE AGAIN SOMETHING TO TAKE ME TO destinationDoc */
              app.pasteInPlace();
              

               

               

              I know im probably going about this all wrong but it's the only thing i can figure out from looking on forum and JS help thanks so much !

               

              Regards,

              Bass

              • 4. Re: Copy contents of 2 layers to new document with javascript
                Larry G. Schneider Adobe Community Professional & MVP

                Instead of activeDocument try app.documents(0) which should be the active document. The one you are adding would be app.documents(1)