Skip to main content
Participant
September 9, 2022
Answered

Is it possible to programmatically modify or create a large number of graphic files at once?

  • September 9, 2022
  • 2 replies
  • 882 views

Hello.

I don't understand graphic tools and their capabilities at all, but I heard that Adobe Illustrator is a very popular tool, so the first thing I decided to do was come here for help.

Let's say I have a picture created with Adove Illustrator that shows a dog in front of a tree. Is it possible in some way to automatically (maybe using some scripts) generate 30 other pictures from this picture, in which instead of a dog there will be other animals (which are separate pictures created in Adobe Illustrator)? Or can it only be done manually?

Thank you.

This topic has been closed for replies.
Correct answer rcraighead

I've used your question as learning opportunity. This script will replace the top page item of the active file with each Symbol in the file and export a PDF. I've included a file with 3 symbols for testing. You could add more. In reality you'd probably want to access the unique "animal" files from a folder.

• Copy the script and save as ".jsx" file in any text editor.
• Run script from "Other Scripts" menu:

 

 

swapSymbols();

function swapSymbols() {
    var aDoc = app.activeDocument;
    for (i = 0; i < aDoc.symbols.length; i++) {
        var oldSymbol = aDoc.pageItems[0];
        var newSymbol = aDoc.symbolItems.add(aDoc.symbols[i]).position = oldSymbol.position;
        var mySymbolName = aDoc.symbols[i].name;
        aDoc.symbolItems[0].translate(0, (-oldSymbol.height + aDoc.symbolItems[0].height));
        oldSymbol.remove();
        mySaveFileToPDF(mySymbolName);
    }
}

function mySaveFileToPDF(mySymbolName) {
    var aDoc = app.activeDocument;
    if (app.documents.length > 0) {
        var saveName = new File('~/Documents/' + mySymbolName + '.pdf');
        saveOpts = new PDFSaveOptions();
        saveOpts.pDFPreset = "[Illustrator Default]";
        PDFSaveOptions.generateThumbnails = true;
        PDFSaveOptions.acrobatLayers = false;
        aDoc.saveAs(saveName, saveOpts);
    }
}

 


Here is the sample file containing 3 Symbols:
dog.pdf

 



2 replies

rcraighead
rcraigheadCorrect answer
Legend
September 9, 2022

I've used your question as learning opportunity. This script will replace the top page item of the active file with each Symbol in the file and export a PDF. I've included a file with 3 symbols for testing. You could add more. In reality you'd probably want to access the unique "animal" files from a folder.

• Copy the script and save as ".jsx" file in any text editor.
• Run script from "Other Scripts" menu:

 

 

swapSymbols();

function swapSymbols() {
    var aDoc = app.activeDocument;
    for (i = 0; i < aDoc.symbols.length; i++) {
        var oldSymbol = aDoc.pageItems[0];
        var newSymbol = aDoc.symbolItems.add(aDoc.symbols[i]).position = oldSymbol.position;
        var mySymbolName = aDoc.symbols[i].name;
        aDoc.symbolItems[0].translate(0, (-oldSymbol.height + aDoc.symbolItems[0].height));
        oldSymbol.remove();
        mySaveFileToPDF(mySymbolName);
    }
}

function mySaveFileToPDF(mySymbolName) {
    var aDoc = app.activeDocument;
    if (app.documents.length > 0) {
        var saveName = new File('~/Documents/' + mySymbolName + '.pdf');
        saveOpts = new PDFSaveOptions();
        saveOpts.pDFPreset = "[Illustrator Default]";
        PDFSaveOptions.generateThumbnails = true;
        PDFSaveOptions.acrobatLayers = false;
        aDoc.saveAs(saveName, saveOpts);
    }
}

 


Here is the sample file containing 3 Symbols:
dog.pdf

 



Participant
September 9, 2022

Wow, thanks a lot. I do not have enough competencies to understand and comment on the code right now, because I am only at the beginning of the journey. It was important for me to understand whether such intervention is possible using code in Adobe Illustrator. Judging by your answer - maybe 🙂 Once again, thank you very much for spending your precious time and helping me!

Kurt Gold
Community Expert
Community Expert
September 9, 2022

Illustrator has a Variables palette that allows to create various dynamic states (e.g. Layer visibility variables or linked files variables). That may be one way to go.

 

Also, Illustrator's symbols come to mind which can be another way.

 

Participant
September 9, 2022

I'll try to look into what you described in your question, thanks a lot!