9 Replies Latest reply on Feb 28, 2014 1:23 AM by Laubender

    [AS][CS6]Paste into from one document to another

    jaguar 0006

      Hello,

       

      I have a group in a first InDesign document and I want to paste it into a frame in another document. Exactly like a Copy / Paste Into.

      I tried this, but that doesn't work:

       

      tell application "Adobe InDesign CS6"

      set MyDocument1 to document 1

      set MyDocument2 to document 2

       

      tell MyDocument1

        set MyGroup to (item 1 of all page items whose label is "group_1")

      end tell

       

      tell MyDocument2

        set MyFrame to (item 1 of all page items whose label is "frame_1")

      end tell

       

      set MyFrame to MyGroup -- doesn't work!

       

      end tell

        • 1. Re: [AS][CS6]Paste into from one document to another
          AS Scripter Level 1

          You could find the graphics file and place it into the other document's frame:

           

          tell application "Adobe InDesign CS6"

                    tell document 1 -- the active doc

                              tell page 1

                                        tell rectangle 1

           

                                                  set gref to item 1 of all graphics of properties

                                                  set fp to ((file path of item link of gref) as string)

           

                                        end tell

                              end tell

                    end tell

           

                    tell document 2

                              tell page 1

            place file fp on rectangle 1

                              end tell

                    end tell

          end tell

          • 2. Re: [AS][CS6]Paste into from one document to another
            jaguar 0006 Level 1

            Hello,

             

            Thank you for your answer.

            I tried what you suggest but I get this error message: "Adobe InDesign CS6 got an error: Can’t get item 1 of all graphics of properties of rectangle 1 of page 1 of document 1":

             

            Screen Shot 2014-02-27 at 09.45.13.png

            • 3. Re: [AS][CS6]Paste into from one document to another
              Laubender Adobe Community Professional & MVP

              @jafuar 0006 – hm…

               

              Just inspecting your screen shot:

               

              How should that work, if there is no graphic placed inside one of the frames? And further, how should that work, if there is no rectangle, but instead a group of rectangles on the page?

               

              Even if a graphic is placed inside that group, wouldn't that be "tell page 1" followed by "tell group 1"? Just musing; I'm no AppleScript guy…

               

              Uwe

              • 4. Re: [AS][CS6]Paste into from one document to another
                jaguar 0006 Level 1

                @Laubender,

                 

                As I explained in my first post, this is a group that I want to copy and "paste into" in my second document.

                This group can contain text frames, images... and I want to copy everything in it.

                • 5. Re: [AS][CS6]Paste into from one document to another
                  Laubender Adobe Community Professional & MVP

                  @jaguar 0006 – it's just that AS scripter's code cannot work in your situation…

                   

                  What you could do without using the UI centric method of "Copy" and "Paste in Place" for selected objects which might working or (more often) not:

                   

                  Add a text frame to your target frame and duplicate your source to the first insertion point of the added text frame in the target.

                   

                  Or simply, I'm not sure if you want that, duplicate your source to the target's page or spread…

                   

                  Uwe

                   

                  Message was edited by: Laubender

                  • 6. Re: [AS][CS6]Paste into from one document to another
                    AS Scripter Level 1

                    Sorry, I thought you were talking about just one graphic.

                     

                    To copy and paste a group, you simply select a group to copy and then tell the app to Copy:

                     

                    tell application "Adobe InDesign CS6"

                     

                              tell document DocA

                      bring to front layout window 1

                     

                                        tell page 1

                                                  select (every group whose label is "GroupA")

                                        end tell

                     

                              end tell

                      copy -- now the group is on the clipboard

                     

                      close document DocA saving no

                     

                    end tell

                     

                    Then navigate to the other document and issue a Paste command in the same way. There is a Paste Into command too, so you should be able to select a target frame and similarly issue the Paste Into command. (I didn't test this.)

                     

                    paste intov : Pastes data from the clipboard into the selected object in the active document window.

                     


                    1 person found this helpful
                    • 7. Re: [AS][CS6]Paste into from one document to another
                      Kevin Parrott Level 2

                      hi jaguar0006

                       

                      try something like this, no error trapping

                       

                       

                      tell application "Adobe InDesign CC"

                                set a_Doc to active document

                                set a_Sel to page items of a_Doc

                       

                                try

                                          set mySpread to spread 1 of active document

                        select (a_Sel)

                        copy

                                end try

                       

                                set active document to document 2

                                set a_Sel2 to page item 1 of active document

                        select (a_Sel2)

                       

                                try

                        paste into

                                end try

                       

                      end tell

                      1 person found this helpful
                      • 8. Re: [AS][CS6]Paste into from one document to another
                        jaguar 0006 Level 1

                        Thank you all!

                         

                        Kevin, your script done exactly what I want. So I have the solution to my problem!

                         

                        However, in the Adobe manual https://www.adobe.com/content/dam/Adobe/en/devnet/indesign/cs55-docs/InDesignScripting/InD esign-ScriptingGuide-AS.pdf

                        (which was recommended to me by Trevor in another discussion ), they advise not use copy and paste: "You can also use copy and paste in InDesign scripting, but scripts using on these methods require that you select objects (to copy) and rely on the current view to set the location of the pasted elements (when you paste). This means that scripts that use copy and paste tend to be more fragile (i.e., more likely to fail) than scripts that use duplicate and move. Whenever possible, try to write scripts that do not depend on the current view or selection state" but I can't specify with a duplicate that I want to get all objects of the group and I can't do the equivalent of a "paste into" with a duplicate.


                        • 9. Re: [AS][CS6]Paste into from one document to another
                          Laubender Adobe Community Professional & MVP
                          … but I can't specify with a duplicate that I want to get all objects of the group and I can't do the equivalent of a "paste into" with a duplicate.

                           

                          @jaguar 0006 – why not? Simply duplicate the group to a specific page or spread of your target document.

                          Duplicate as method on Group objects takes a Page object as argument. Could be a page in the same document, could be a page in another open document!

                           

                          I cannot assist in AppleScript code, but here is a ExtendScript snippet, that does exactly that.

                          It will work when executed from the ESTK (ExtendScript Toolkit) or saved as text only with a *.jsx suffix from your Scripts Panel.

                           

                          Have your two documents open (and only them!) when executing this snippet. The source document with the group must be the active one.

                           

                          This example is NOT working with the label property. Label as property is a bit unfortunate for ExtendScript, because there is no method itemByLabel("labelString").

                           

                          Instead I used the name property. You can name your objects simply by going to the Layers Panel and rename an object on the spread. Or assign a name directly by scripting.

                           

                          In ExtendScript for a selected object that would be:

                           

                          app.selection[0].name = "Group_1";
                          

                           

                          Or in your case you could loop all Group objects in your document and give the name according to the label property:

                           

                          for(var n=0;n<app.documents[0].groups.length;n++){
                          
                               if(app.documents[0].groups[n].label === "Group_1"){
                                    app.documents[0].groups[n].name = app.documents[0].groups[n].label;
                                    };
                               break;
                               };
                          

                           

                           

                          So the following snippet is just a use case for the duplicate() method, if there is a group in the source document named "Group_1" and a "frame" (could be any kind) named "Frame_1" is sitting on a page (not the pasteboard!) in the target document (working in InDesign CS5 and above):

                           

                          var sourceDoc = app.activeDocument;
                          var targetDoc = app.documents[1];
                          
                          var sourceGroup = sourceDoc.pageItems.itemByName("Group_1");
                          var targetPage = targetDoc.pageItems.itemByName("Frame_1").parentPage;
                          
                          sourceGroup.duplicate(targetPage);
                          

                           

                          There are some pitfalls though: if the target frame is on the pasteboard, we have to do some extra calculations, if there are other documents open beneath source and target document, if the target and source group/frame are nested in other objects or anchored to other objects etc.pp.

                           

                          The method duplicate() should do the same in AppleScript.

                           

                          Uwe