Copy link to clipboard
Copied
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
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 = sourceDoc.artboards[artbs-1]; // get actual artboard
ABsRect = ABs.artboardRect; // get Rectangle
ABsNames = ABs.name; // get Name
ABsInfo = [ABsRect, ABsNames]; // get Rectangle and Name
sourceDoc.selection = null; // deselect everything
sourceDoc.artboards.setActiveArtboardIndex (artbs-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;
layerState = [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
; ilayer.visible = layerstate
[0]; // already a Boolean value, no need to convert ilayer.locked = layerstate
[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
[0]); newAB.name = ABsInfo
[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
.duplicate(destDoc.layers[sel .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.name + "\t"; // had to use tab (insted of \r) to have the list "inline". Prompt only allows 4 rows in windows
}
return msg;
}
Copy link to clipboard
Copied
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:
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
That’s great…very helpful. Thanks again!
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
yes, that script was basically custom made for that specific file structure, do you need something similar?
Copy link to clipboard
Copied
Could you share with me what file structure / organization I should use with it?
Again, many thanks. This is a very useful!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 = ABs.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:
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
ACEATEND);
I'm very grateful for your help!
Copy link to clipboard
Copied
Ah! I just looked above and saw your comment that both files need to share layer names, so I copy/pasted the contents of my source file (with Paste Remembers Layers enabled in the layer palette), and then ran the script again, looks like it did import! Wow, this is spectacular, Carlos you are a hero.
Copy link to clipboard
Copied
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.
Does that also count for sub-layers? Im testing this file on document which has just 1 layer named "Layer 1". Both the destination have this same layer name.
I also tried adding 1 sub-layer with the same name, still keeps pushing out this error "Error 1302"
did some quick check. Not sure why but docs.name returns error for me in #90.
I see other docs using docs[i].name. I guess this also is one of those script destroyed by the forum update
Copy link to clipboard
Copied
i was looking at your script, and It is pretty awesome. i was wondering if it could be modified to use with Skala, meaning- I wouldn't need another file open at the time.
Copy link to clipboard
Copied
thanks Paul, I have no idea how Skala works, I'm on Windows.
Copy link to clipboard
Copied
CarlosCanto you are genius bro. Thanks a lot. God bless you.
Copy link to clipboard
Copied
thanks bro
Copy link to clipboard
Copied
Im trying to fix the script but im keep running into issues. Its all fine untill the part the arboards needs to be created. Since this new forum design destroyed all scripts in the loop parts. I tried a different combinations but it seems the array isnt made properly anymore at the loop at #27
I dont see a push state or some to add to the list, i tried add the addArtboards in the loop but that it returns an error.
COuld some paste a working version in a proper way here. When i try to fix it, i only get 2 artboards instead 4. WHen i alter the script a a bit i do 4 artboards, but the content is nver in the proper locations and it adds all artboards 2 times
I tried fix the initial script in this loop. But when it need to make the artboards, somehow it only has 2. But when i do a check with an alert inside that loop, it works fine and gives 4 artboards in return, each with their own rectangle measurements for the artboard
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 = sourceDoc.artboards[artbs[i]-1]; // get actual artboard
ABsRect = ABs.artboardRect; // get Rectangle
ABsNames = ABs.name; // get Name
ABsInfo = [ABsRect, ABsNames]; // 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);
}
}
Copy link to clipboard
Copied
Well i got his original script working again, not sure what happened but i altered the first part quite a lot. In my first altered version, it would copy/paste make artboard, so it was switching docs all the time, looked quite slow. Then i changed the method to i believe Carlos first setup, but i never got his to work. So i added a push in the loop so all AB info is stored in a list and gets retrieved at the end. Result is i guess 70% than my initial adjustment of the code. It feels super fast, sort of 😉
Im also trying to add a GUI to this script, i think its easier and cleaner.
I do have some issues now with adding stuff to a new document. Artwork is on the artboards or at the correct location.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
I have a document with 10 artboards of different sizes and I wanted to copy it to another document so what I did was use "Save As" to save the existing document with a new file name and then delete everything in this file and continue with new atwork with the same artboards in the same position.