Skip to main content
Participant
December 10, 2024
Question

variable set > batch export png > action > issue with the same name

  • December 10, 2024
  • 1 reply
  • 444 views

Hi,
I have only one artboard on which some data is modified with a set of variables.
I would like to create an action that allows you to export it to png using different names for each row of the set.

Of course I use the actions panel, but exporting to a specific folder the system uses the same name as the output file, effectively replacing the file just created. So instead of having 30 different pngs, I only have 1 (the last one of the set).

Can anyone help me?

This topic has been closed for replies.

1 reply

Participant
December 28, 2024
quote

Hi,
I have only one artboard on which some data is modified with a set of variables.
I would like to create an action that allows you to export it to png using different names for each row of the set.

Of course I use the actions panel, but exporting to a specific folder the system uses the same name as the output file, effectively replacing the file just created. So instead of having 30 different pngs, I only have 1 (the last one of the set).

Can anyone help me?


By @Andrea38138254hjmgTellCulver

 

Certainly! To create multiple PNG files with different names for each row of the set, you need to create an action in Adobe Illustrator, but also use a bit of automation to avoid overwriting files. Since Illustrator’s actions don’t directly support loops or variable-specific file naming, you will need to make use of Illustrator’s Variables panel and scripting (JavaScript).

Step-by-step approach:

  1. Prepare the Variables:

    • Make sure your artboard uses data variables (for example, from a CSV or text file) to adjust the artwork's content for each row.
    • This means you will have an Illustrator file with placeholder text or image areas that get replaced by the variable data.
  2. Setup your Action (Manual Steps for Exporting):

    • Go to Window > Variables and make sure your artwork is linked to the correct variable data (from a CSV or text file).
    • You can create a simple action that exports the artboard to a PNG. Go to Window > Actions to open the Actions panel.
    • Create a new action by clicking the New Action button, name it (e.g., "Export PNG"), and start recording the steps:
      • Choose File > Export > Export As… (or use File > Export for Screens if you'd prefer).
      • Choose PNG as the format.
      • Select your destination folder.
      • Finish the action.
    • At this point, you have an action that exports to a PNG, but it will save with the same filename each time, overwriting the previous export.
  3. Using Variables for Dynamic Export Names: Illustrator’s Actions panel doesn't support automatic naming of files based on the variable data. You need to either modify the file name before exporting it for each variable or use a script.

  4. Write a Script to Automate Exporting (with Variable-based Names): Here’s a simple JavaScript that you can run in Illustrator to export the artboard as PNGs with different filenames based on your variable data.

    • Open ExtendScript Toolkit (or the JavaScript Console within Illustrator) and paste the following script:

 

#target illustrator

// Set up your folder and file names
var doc = app.activeDocument; // Get the active document
var exportFolder = Folder.selectDialog("Select the folder to save PNGs"); // Choose export folder

// Check if a folder is selected
if (exportFolder != null) {
    var csvFile = File.openDialog("Select your CSV file", "*.csv"); // Choose CSV with variable data
    
    // Open the CSV file
    if (csvFile != null) {
        csvFile.open('r');
        var rows = [];
        
        // Read the CSV content into an array (assuming the CSV has one value per row)
        while (!csvFile.eof) {
            var row = csvFile.readln().split(','); // Split by commas, assuming CSV format
            rows.push(row);
        }
        csvFile.close();
        
        // Loop through each row in the CSV
        for (var i = 0; i < rows.length; i++) {
            var rowData = rows[i][0]; // Assuming each row has a single column (adjust if your CSV is structured differently)
            
            // Apply the variable data to the artboard (this assumes you are using text variables in your document)
            doc.textFrames.getByName("TextPlaceholder").contents = rowData; // Replace with your text placeholder name
            
            // Export the file as PNG
            var exportOptions = new ExportOptionsPNG24();
            exportOptions.artBoardClipping = true;
            exportOptions.antiAliasing = true;
            exportOptions.transparency = true;
            
            // Construct the file name based on the data (e.g., Row_1.png, Row_2.png)
            var fileName = "Exported_" + rowData + ".png";
            var exportFile = new File(exportFolder.fsName + "/" + fileName);
            
            doc.exportFile(exportFile, ExportType.PNG24, exportOptions);
        }
        alert("Export complete!");
    }
}
​

 

 

  • Running the Script:

    • Save the script as a .jsx file and run it through File > Scripts > Other Script....
    • The script will prompt you to select a folder and then ask you for a CSV file containing your variable data (each row will be used for a different export).
    • The script will replace the placeholder text or variable content in the document with the corresponding value from each row and export it as a PNG to the selected folder, appending the row data to the filename.
  • Benefits of this Approach:

    • No Overwriting: Each export will have a unique name based on the row data.
    • Automation: You avoid manually editing the file name or re-running the export step multiple times.
    • Customization: You can easily modify the script to accommodate different variable types, such as images or different layers.