1 2 Previous Next 44 Replies Latest reply: Feb 11, 2015 9:43 PM by CarlosCanto RSS

    Copy artboard (and art) to another document

    timlogochair Community Member

      Is there a way to write a script to copy a selected/chosen artboard (and it's contents) to another opened document, placing it in exactly the same place on the global x/y coordinates?  I'm either unable to find this feature built in to Illustrator, or it's simply missing.  Any help is greatly appreciated.

       

      Thanks!

      Tim

        • 1. Re: Copy artboard (and art) to another document
          CarlosCanto MVP

          there's no one command to do that. You'll have to get the size/placement of the artboard and recreate in the destination document. Then is a matter of looping thru all pageItems and duplicate them to the new artboard.

          • 2. Re: Copy artboard (and art) to another document
            timlogochair Community Member

            So basically it would have to be a separate script for each artboard we’ want to copy, right?  If that’s the case that wouldn’t save us much/if any efficiency.  Was worth a shot, and can’t hurt to ask J

            • 3. Re: Copy artboard (and art) to another document
              CarlosCanto MVP

              if you need to replicate all the artboards, you could loop thru all of them. If you need only certain artboards you could either ask (which ones, that would be the easy way) thru scripting or select some pieces live in each of the artboards and add logic to find out the artboards indexes.

               

              what version are you using? in CS5 there's a function to select all objects in a given artboard

              • 4. Re: Copy artboard (and art) to another document
                timlogochair Community Member

                Yes, I’m using CS5.  It would be a case of only needing to pick and choose which artboards to copy as needed from the original template onto an existing document.  The nice thing is, the documents and all of their artboards (or vacancies) are all in the same location (on all of the documents), so if I can get a script it would ideally seat the copied artboards/artwork into the same vacant location.  In other words, all of our documents started from the same template…and we now have hundreds of files from this original template.  We have now had a need to add a few artboards to the original template.  Now that we’ve added them to the template, we must go back and add only the new artboards (to the same vacant location) on all of the other hundreds of files.  Trying to explain it clearly, but I’m not sure, am I making sense?

                • 5. Re: Copy artboard (and art) to another document
                  CarlosCanto MVP

                  it does make sense, are you writing the script?

                  • 6. Re: Copy artboard (and art) to another document
                    timlogochair Community Member

                    I wish.  Unfortunately, I would probably need some pretty detailed guidance to pull it off by myself.

                    • 7. Re: Copy artboard (and art) to another document
                      CarlosCanto MVP

                      I'll give it a try....

                      • 8. Re: Copy artboard (and art) to another document
                        timlogochair Community Member

                        Thanks Carlos.  Do you need any more info?

                        • 9. Re: Copy artboard (and art) to another document
                          CarlosCanto MVP

                          Hi Tim, I haven't had a chance to work on you project...one question...what is the more complex layer structure you would potentially have. I mean how deep would your layers within layers within layers go?

                          • 10. Re: Copy artboard (and art) to another document
                            timlogochair Community Member

                            There are just three layers of depth in these files.  “Template”, “Approvals”, and “Art”.  The “Approvals” and “Template” layers will be locked (but should be copied/duplicated onto the other document that has the exact same layer structure/names/locked status.)

                             

                             

                             

                            Does that answer what you’re needing to know?  Let me know if you need something else.

                             

                             

                             

                            Thanks,

                            Tim

                            • 12. Re: Copy artboard (and art) to another document
                              timlogochair Community Member

                              There are no layers that I created as “sub-layers”.  I think I’m a little new to the “sub-layer” terminology.  There are objects and object “groups” that exist within the “Template” and approval layers, but none that were created as “sub-layers” containing multiple sets of object groups etc.  Am I making sense or do you need to see an example?

                               

                               

                               

                              Thanks,

                              Tim

                              • 13. Re: Copy artboard (and art) to another document
                                timlogochair Community Member

                                Let me just say that “Actions” in Illustrator CS5 are worthless.  Even trying to create a manual “action” to do this is proving impossible because of the limitations of this feature.  It doesn’t record 50% of the actions a user takes.  Can’t even record the steps to create a new artboard.  Very frustrating (again) as I try to get something done using actions in illustrator..

                                 

                                 

                                 

                                Sorry for the vent, but all that to say, I am grateful for your help with scripting this.  Let me know if you need any other info from me.

                                 

                                 

                                 

                                Thanks,

                                Tim

                                • 14. Re: Copy artboard (and art) to another document
                                  Muppet Mark Community Member

                                  Tim, You will NOT be able to do any of this with actions ( well so I think )… Further more I think script could do this ( but there would be serveral limitations )…

                                  • 15. Re: Copy artboard (and art) to another document
                                    timlogochair Community Member

                                    I'm ok with some limitations, but if there's a way do automate/speed up any portion of this...even if have to run 2 scripts...it would be a great help. We have a ton of artboards/documents that we are working with.

                                    • 16. Re: Copy artboard (and art) to another document
                                      Muppet Mark Community Member

                                      Something that springs to mind straight away… This could become a RPITA both your artboards and there relative artwork must be separate… AI lets you do artboards in formatted rows etc. or completly random and art can exist across multi-artboards… I would hop you are dealing with the first of these?

                                      • 17. Re: Copy artboard (and art) to another document
                                        CarlosCanto MVP

                                        that was my main concern, it could get real messy, but if all docs are based on the same template that part would be covered. The other issue would be nested layers, now it seems there's only main layers, it's getting less complicated...

                                        • 18. Re: Copy artboard (and art) to another document
                                          Muppet Mark Community Member

                                          There are very limited opions when working with artboards… Using the select method and using app.copy() app.paste() may be one route… I don't know if 'paste remember layers' is a writable boolean in the pref's or you could just ask the user opts for this before running…? Not tried it myself so it would need testing… I try NOT to use the clipboard where ever possible… Anyhows I don't think it's a 15 minute re-hash of some code I already have…

                                          • 19. Re: Copy artboard (and art) to another document
                                            CarlosCanto MVP

                                            yeah, copy/paste is a headache, I was thinking selecting all on a given artboard, then duplicate each item in selection to the destination document. That's the process I did with the "open multipage pfd" script, but you're right, it is not a 15 minute thing.

                                            • 20. Re: Copy artboard (and art) to another document
                                              Muppet Mark Community Member

                                              Carlos, I had on my to do list a PDF page importer ( been there a little while )… Not had the oportunity to look at your script yet ( but I will )… I have several issues with AI and it's artboards Im glad I missed CS4 where they were just plain $h1t at least they put some sugar on it in CS5 but they still smell and taste like…

                                              • 21. Re: Copy artboard (and art) to another document
                                                timlogochair Community Member

                                                Do you guys need to see a sample file?

                                                • 22. Re: Copy artboard (and art) to another document
                                                  CarlosCanto MVP

                                                  it wouldn't hurt to have one, post it.

                                                  • 23. Re: Copy artboard (and art) to another document
                                                    timlogochair Community Member

                                                    I will send a PM to you and Mark.  Some of the artwork is proprietary (licensed marks) so I can't just post the files online.

                                                     

                                                    Thanks,

                                                    Tim

                                                    • 24. Re: Copy artboard (and art) to another document
                                                      timlogochair Community Member

                                                      Carlos - PM me the email address to send the sample files (template and destination file) to. 

                                                       

                                                      Thanks so much!

                                                      • 25. Re: Copy artboard (and art) to another document
                                                        timlogochair Community Member

                                                        Hey guys -

                                                        Was wondering if anyone has had a chance to look at this?  Just curious if it's proving to be more difficult than originally anticipated.

                                                         

                                                        Thanks,
                                                        Tim

                                                        • 26. Re: Copy artboard (and art) to another document
                                                          CarlosCanto MVP

                                                          it was in fact more dificult than I had anticipated...in part because of the limitations of the Illustrator scripting capabilities, in part your document set up...but it is "almost" done.

                                                          • 27. Re: Copy artboard (and art) to another document
                                                            CarlosCanto MVP

                                                            Hi Tim, here you go, open both your template and your destination document and run the script

                                                             

                                                            #target illustrator
                                                            
                                                            
                                                            // script.name = timLCdupArtboards.jsx; 
                                                            // script.description = duplicates provided artboards to another open document;
                                                            // script.required = requires CS5, and both source and destination documenets (with the same layer structure) open
                                                            // script.parent = CarlosCanto // 02/07/12;  
                                                            // script.elegant = false;
                                                            
                                                            
                                                            // Notes: use only in documents with NO sublayers, 
                                                            
                                                            
                                                            
                                                            
                                                            var docList = doclist(); // get a list of open docs
                                                            
                                                            
                                                            var source = prompt ("Enter Source Document (Index Number)\r\r" + docList, 0, "Copy Artboards"); // get source doc name index
                                                            if (source!=null) {// quit if pressed Cancel
                                                                var dest = prompt ("Enter Destination Document (Index Number)\r\r" + docList, 1, "Copy Artboards"); // get destination doc name index
                                                                if (dest!=null) {// quit if pressed Cancel
                                                                    var absstring = prompt ("Enter Indexes of Artboards to copy (comma separated)", "25,37,16,19,34,35,36", "Copy Artboards"); // get list of artboards to copy
                                                                    if (absstring!=null) {// quit if pressed Cancel
                                                            
                                                            
                                                                        var artbs = absstring.split (","); // turn list into an array
                                                                        var absCount = artbs.length; // get artboards count
                                                            
                                                            
                                                                        var sourceDoc = app.documents[source]; // get actual docs
                                                                        var destDoc = app.documents[dest];
                                                            
                                                                        // get layer visible/lock info & unlock and make visible all layers
                                                                        var sourceDocLayerState = unlockUnhideLayers(sourceDoc);
                                                                        var destDocLayerState = unlockUnhideLayers(destDoc);
                                                            
                                                                        sourceDoc.activate(); // activate source otherwise it is not able to access selection
                                                            
                                                            
                                                                        var ABs = []; // array to hold of artboard objects to copy
                                                                        var ABsRect = []; // array to hold artboards Rectangles
                                                                        var ABsNames = []; // array to hold artboard names
                                                                        var ABsInfo = []; // array to hold [Rect, Names]
                                                                        for (i=0; i<absCount; i++) {
                                                                            ABs[i] = sourceDoc.artboards[artbs[i]-1]; // get actual artboard
                                                                            ABsRect[i] = ABs[i].artboardRect; // get Rectangle
                                                                            ABsNames[i] = ABs[i].name; // get Name
                                                                            ABsInfo[i] = [ABsRect[i], ABsNames[i]]; // get Rectangle and Name
                                                            
                                                                            sourceDoc.selection = null; // deselect everything
                                                                            sourceDoc.artboards.setActiveArtboardIndex (artbs[i]-1); // activate each artboard
                                                                            sourceDoc.selectObjectsOnActiveArtboard(); // select all in artboard
                                                                            sel = sourceDoc.selection; // get selection
                                                                            moveObjects(sel, destDoc); // move selection
                                                                        }
                                                            
                                                            
                                                                        addArtboards(destDoc, ABsInfo); // recreate artboards in destination document
                                                            
                                                                        // restore layer original state
                                                                        lockHideLayers(sourceDoc, sourceDocLayerState);
                                                                        lockHideLayers(destDoc, destDocLayerState);
                                                                    }
                                                                }
                                                            }
                                                            
                                                            
                                                            
                                                            
                                                            function unlockUnhideLayers(doc) {
                                                                      // get visible state of each layer, and show/unlock layers
                                                                      var layerState = []; // array to hold layer visibility
                                                                      var layerCount = doc.layers.length; // layer count
                                                            
                                                            
                                                                      // get layer visibility, and turn all layers on
                                                                      for (i=0; i<layerCount; i++) {
                                                                                var ilayer = doc.layers[i];
                                                                                layerState[i] = [ilayer.visible, ilayer.locked];
                                                                                ilayer.visible = true;
                                                                    ilayer.locked = false;
                                                                      }
                                                                return layerState;
                                                            }
                                                            
                                                            
                                                            function lockHideLayers(doc, layerstate) {
                                                                      // restore layer visibility
                                                                var layerCount = doc.layers.length; // layer count
                                                                      for (k=0; k<layerCount; k++) {
                                                                                var ilayer = doc.layers[k];
                                                                    ilayer.visible = layerstate[k][0]; // already a Boolean value, no need to convert
                                                                    ilayer.locked = layerstate[k][1]; // already a Boolean value, no need to convert
                                                                      }
                                                            }
                                                            
                                                            
                                                            
                                                            
                                                            // create artboards in destination doc, using the info in absInfo (abRect, Name)
                                                            function addArtboards(doc, absInfo) {
                                                                var destDoc = doc;
                                                                var absCount = absInfo.length;
                                                                destDoc.activate();
                                                                for (j=0; j<absCount; j++) {
                                                                    var newAB = destDoc.artboards.add(ABsInfo[j][0]);
                                                                    newAB.name = ABsInfo[j][1];
                                                            
                                                                }
                                                            }
                                                            
                                                            
                                                            // move selected objects (sel) to destination document
                                                            function moveObjects(sel, destDoc) {
                                                                for (k=0; k<sel.length; k++) { 
                                                                    // duplicate items to the same layer in dest document, give both documents have the same layer structure
                                                                    var newItem = sel[k].duplicate(destDoc.layers[sel[k].layer.name],ElementPlacement.PLACEATEND);
                                                                }
                                                            }
                                                            
                                                            
                                                            // get a list of open documents, separated by tabs
                                                            function doclist() {
                                                                var docs = app.documents;
                                                                    msg = "";
                                                                for (i=0; i<docs.length; i++) {
                                                                    msg += i + ". " + docs[i].name + "\t"; // had to use tab (insted of \r) to have the list "inline". Prompt only allows 4 rows in windows
                                                                }
                                                                return msg;
                                                            }
                                                            
                                                            • 28. Re: Copy artboard (and art) to another document
                                                              timlogochair Community Member

                                                              Carlos - wow.  This is great, thank you so much!

                                                               

                                                              This seems to be working perfectly and will save TONS of time for us.

                                                               

                                                              A couple of questions:

                                                              1. Is it possible to select multiple destinations via the index chooser via comma separation?  In other words if I have 5 documents open that I want to run this same script on, with the same artboards selections, can I do it all at the same time?  Not a big deal since I can run the same script for each document, it would just save the multiple dialogue boxes for each document.
                                                              2. Is there a way to sort all of the artboards by artboard name (via script) in the destination document (including the newly created artboards)?  Either as a separate script or at the end of this one?
                                                              3. You rock - thanks so much for your help.
                                                              • 29. Re: Copy artboard (and art) to another document
                                                                timlogochair Community Member

                                                                One more question.

                                                                   4.  Is it possible to select the top layer (it's called "Art") after the bottom two layers are locked back, instead of leaving the selected layer on the layer that is locked?

                                                                 

                                                                Thanks!

                                                                • 30. Re: Copy artboard (and art) to another document
                                                                  CarlosCanto MVP

                                                                  Hi Tim,

                                                                   

                                                                  1. I was afraid you were going to ask for that

                                                                  2. I'm not sure, it might be possible

                                                                  3. thanks

                                                                  4. add the following line after line 54, destDoc.activeLayer = destDoc.layers[0]; // activate "Art" layer

                                                                   

                                                                  so it looks like this

                                                                   

                                                                  line 54            lockHideLayers(destDoc, destDocLayerState);

                                                                  line 55            destDoc.activeLayer = destDoc.layers[0]; // activate "Art" layer

                                                                   

                                                                  visually it will look like nothing happened, some other layer "looks" active, but the Art layer is the active one, the screen will update after you switch to another document and come back.

                                                                  • 31. Re: Copy artboard (and art) to another document
                                                                    timlogochair Community Member

                                                                    That’s great…very helpful.  Thanks again!

                                                                    • 32. Re: Copy artboard (and art) to another document
                                                                      harry_earthling Community Member

                                                                      This is very useful. Thank you for sharring this!

                                                                       

                                                                      I am attempting to use the script however it only partially executes before returning an error.

                                                                      "Error 1302: No such element"

                                                                       

                                                                      In order to use this script must I name my layers or artboards in a specific manor?

                                                                       

                                                                      error.jpg

                                                                      • 33. Re: Copy artboard (and art) to another document
                                                                        CarlosCanto MVP

                                                                        yes, that script was basically custom made for that specific file structure, do you need something similar?

                                                                        • 34. Re: Copy artboard (and art) to another document
                                                                          harry_earthling Community Member

                                                                          Could you share with me what file structure / organization I should use with it?

                                                                          Again, many thanks. This is a very useful!

                                                                          • 35. Re: Copy artboard (and art) to another document
                                                                            CarlosCanto MVP

                                                                            your destination Document must have the same Layer Names you have in your Source Document, that's all is required...and both docs to be open.

                                                                            • 36. Re: Copy artboard (and art) to another document
                                                                              RicardoParker Community Member

                                                                              I ran into this problem today, which I think is bad design by Adobe... keeping in mind Illustrator is an awesome program, but just not perfect.

                                                                               

                                                                              Here is how I got around it, which may be a good solution for you (running scripts are a real pain, IMO): I was using 10 story boards and needed 1 more, but Illustrator would give me this message saying it wasn't possible to do it outside boundaires. I deleted some storyboards, to no avail. So then I did this:

                                                                               

                                                                              Deleted all of them, except one, which wasn't possible to delete. Then I reduced the size of that one to a miniscule storyboard. Then I added 20 storyboards, which is more than what I'll need. Seems like you can go infinite on storyboards.

                                                                               

                                                                              Deleting storyboards may seem like a bad way to go about it, but it isn't if you will write down the 4 coordinates for each storyboard: width, height, and x and y coordinates. Then just go back to the new [miniscule] storyboards you created and change them to the numbers they used to be. Hope this helps.

                                                                               

                                                                              www.imaginativedesign.co

                                                                              • 37. Re: Copy artboard (and art) to another document
                                                                                nickolaspeter Community Member

                                                                                Hi Carlos and community memembers! 

                                                                                I was trying to merge a UI design file with a bunch of little differently sized sets of artboards (for icons and such), and was looking for a way to easily merge my file with a team member's.  I was happy to find this script, but it didn't work for me (maybe because I'm on CS6?)

                                                                                 

                                                                                I get this error:


                                                                                Error 1200: an illustrator error occurred: 1346458189 ('MRAP')

                                                                                Line: 47

                                                                                ->  AbsRect[i] = ABs[i].artboardRect; // get Rectangle

                                                                                 

                                                                                Despite it not working, I think what Carlos has done is tremendous and I would personally be willing to pay for such a script if Adobe doesn't implement this very function. 

                                                                                 

                                                                                Also, for anyone looking for a semi-manual, but still time saving method to do this, you can refer to this discussion I just had with Monika on the forum:

                                                                                http://forums.adobe.com/message/6281966

                                                                                • 38. Re: Copy artboard (and art) to another document
                                                                                  CarlosCanto MVP

                                                                                  Hi nickolas, the script works fine in CS6, the error you're getting is caused by the entering the wrong artboard index to copy.

                                                                                   

                                                                                  in the third window, enter the artboard index to copy, if you have 2 artboards and key in index 3, you'll get the error in line 47.

                                                                                  • 39. Re: Copy artboard (and art) to another document
                                                                                    nickolaspeter Community Member

                                                                                    Hm, maybe I'm doing something else wrong.  I get an error if I just enter 1 (I had started with, 1,2,3, etc). 

                                                                                     

                                                                                    I just ran it again and got:

                                                                                     

                                                                                    Error 1302: No such element

                                                                                    Line: 118

                                                                                    -> var newItem =

                                                                                    self[k].duplicate(destDoc.layers[sel[k].layer.name],ElementPlacement.PL

                                                                                    ACEATEND);

                                                                                     

                                                                                    I'm very grateful for your help!

                                                                                    1 2 Previous Next