Collect objects from different files to one

Explorer ,
Nov 22, 2020 Nov 22, 2020

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.

TOPICS
Scripting

Views

133

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 22, 2020 Nov 22, 2020

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]]);
  }
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 22, 2020 Nov 22, 2020

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?

 

Be_Illustrator_0-1606020296405.png

Be_Illustrator_1-1606020316973.png

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 22, 2020 Nov 22, 2020

Copy link to clipboard

Copied

Sorry. It really works with more clearly files

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 22, 2020 Nov 22, 2020

Copy link to clipboard

Copied

Thanks. You've made my day

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 22, 2020 Nov 22, 2020

Copy link to clipboard

Copied

👍

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 22, 2020 Nov 22, 2020

Copy link to clipboard

Copied

could it work for "Group" objects?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 23, 2020 Nov 23, 2020

Copy link to clipboard

Copied

LATEST

@Be_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]]);
  }
}

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines