Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I've written a simple script to open two documents in Adobe Illustrator (File -> Scripts) and apply some commands to those documents.
The purpose of the script; with no documents open in Illustrator, the script will:
Open the required documents.
Load an XML variable library into those documents.
Display the dataset in that library (there is only one dataset).
Save the file in a given location.
Close the file.
The script:
var doc_1 = open(File("C:/file1.ai"));
var doc_2 = open(File("C:/file2.ai"));
var sourceDoc;
var targetFile;
var options = new IllustratorSaveOptions();
for (var i = 0; i < app.documents.length; i++ )
sourceDoc = app.documents[i];
sourceDoc.importVariables(new File("C:/variables.xml"));
sourceDoc.dataSets[0].display();
targetFile = new File("C:/output" + sourceDoc.name + '.ai');
sourceDoc.saveAs( targetFile, options );
sourceDoc.close();
catch(err)
alert(err);
This code works only for the
last opened file
(file2.ai). file1.ai is never touched, almost as if there is no loop.
What could be causing this?
When closing the first file in the loop you just moved
app.documents[1]
to
app.documents[0]
You want top loop through them backwards
try your loop with
for (var i = app.documents.length; i >0 ; i-- )
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.