Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

Batch combine files into one illustrator document - how to open target document?

$
0
0

I am making a script which will:

 

1) Open a folder of Illustrator files

2) Open each file in the folder (these files are called the source files)

3) Select all the contents of the source file

4) Copy the contents of the source file

5) Paste these contents into a target file as a new layer

6) Ensure the new layer has the same name as the old source file

 

 

However, I don't know how to tell Illustrator where my target file is. How can I do this?

 

Also, when I paste, how can I turn off paste rembers layers. (So the layers get pasted into the new layer that has the same name as the old document).

 

Here is my code:

 

 

// JavaScript Document

 

 

//Set up vairaibles

var destDoc, sourceDoc, sourceFolder;

 

 

// Select the source folder.

sourceFolder = Folder.selectDialog('Select the folder with Illustrator files that you want to mere into one', '~');

 

 

// If a valid folder is selected

if (sourceFolder != null) {

          files = new Array();

 

 

          // Get all files matching the pattern

          files = sourceFolder.getFiles();

 

 

          if (files.length > 0) {

                    // Get the destination to save the files

                    destDoc = document.selectDialog('Select the final saved document', '~');

                    for (i = 0; i < files.length; i++) {

                              sourceDoc = app.open(files[i]); // returns the document object

 

                              var myLayers = sourceDoc.layers; // All layers in Active Document

 

 

                              //Go through all layers of source document and copy artwork

                              for (i = 0; i < myLayers.length; i++) {

                                        myLayers[i].hasSelectedArtwork = true;

                              };

 

 

                              with(sourceDoc) {

                                        var count = pageItems.length;

                                        for (var i = 0; i < count; i++) {

                                                  pageItems[i].selected = true;

                                        }

                                        redraw();

                                        copy();

                                        for (var i = 0; i < count; i++) {

                                                  pageItems[i].selected = false;

                                        }

 

 

                              }

 

 

                              //Create a new title variable that has the title of the source document

                              var title = sourceDoc.name;

                              var title = title.substring(0, title.length - 4); //(remove extension from name)

                              //Close the Source Document

                              sourceDoc.close(SaveOptions.DONOTSAVECHANGES);

 

 

 

 

                              //Open the Destination Document and create a new layer in it that is named after the title variation

                              var newLayer = destDoc.layers.add();

                              newLayer.name = title;

 

 

                              //Paste into this new layer

                              destDoc = app.paste();

 

 

                    }

          }

          else {

                    alert('No matching files found');

          }

 

}

 

Thanks in advance for any help   

 

Edit: Also, when pasting, how can I paste in place instead of just pasting.


Viewing all articles
Browse latest Browse all 12845

Trending Articles