Collect objects from different files to one
Copy link to clipboard
Copied
Hi guys
I need the script to collect objects from different files to one
1.I have a folder with Ai* files whicj namedlike 1,2,3,4...
2. Ineed to copy сontent from each files to one document to different layers whicn named like 1.2.3.4.5. or something like this.
It will be enough if script execute command "select all" - "copy"- "Paste" . The main goal is collect objects from different files to one.
And one small detail. I do not know Java.
I have small budget if needed.
Explore related tutorials & articles
Copy link to clipboard
Copied
// "copy-n-paste" pageItems
// from open docs named 1, 2, 3, ... , n
// to corresponding layers in new untitled doc
var docs = app.documents;
var docNames = [];
for (var i = 0; i < docs.length; i++) {
docNames.push(docs[i].name);
docNames.sort();
}
var targetDoc = app.documents.add();
for (var i = docNames.length - 1; i > -1; i--) {
docs[docNames[i]].activate();
var layer1 = targetDoc.layers.add();
layer1.name = docNames[i];
for (var j = 0; j < app.activeDocument.pageItems.length; j ++) {
app.activeDocument.pageItems[j].duplicate(targetDoc.layers[docNames[i]]);
}
}
Copy link to clipboard
Copied
It is good. Thank you a lot.
But I have some trouble with copied some objects. Please check my screenshots.
The first is my source file. The second is file after processing by script.
All select layers are copies.
P.S. I think it is my trouble and I should give your more information about files?
Copy link to clipboard
Copied
Sorry. It really works with more clearly files
Copy link to clipboard
Copied
Thanks. You've made my day
Copy link to clipboard
Copied
👍
Copy link to clipboard
Copied
could it work for "Group" objects?
Copy link to clipboard
Copied
@Berezin_Illustrator There was an oversight in the above script. It copied all pageItems, so it copied groups and separately copied paths within groups, i.e. it copyed grouped-paths twice. (The same with compound paths.) This should rectify that:
// "copy-n-paste" pageItems
// from open docs named 1, 2, 3, ... , n
// to corresponding layers in new untitled doc
var docs = app.documents;
var docNames = [];
for (var i = 0; i < docs.length; i++) {
docNames.push(docs[i].name);
docNames.sort();
}
var targetDoc = app.documents.add();
for (var i = docNames.length - 1; i > -1; i--) {
docs[docNames[i]].activate();
var layer1 = targetDoc.layers.add();
layer1.name = docNames[i];
label: for (var j = 0; j < app.activeDocument.pageItems.length; j ++) {
var item = app.activeDocument.pageItems[j];
if (item.parent.typename == "GroupItem" ||
item.parent.typename == "CompoundPathItem") {
continue label;
}
item.duplicate(targetDoc.layers[docNames[i]]);
}
}

