0

In Illustrator CC 23.0.1 is it possible to use the 'source' folder of a file as the 'destination' when using Illustrator's batch processing options via the 'Actions' window?

I have a directory of 200 folders, each with 5 sub-directories containing 2 Illustrator files each. I need to convert the .ai files to .svg files. When recording an action, the 'Save As' part of the action saves the location of the first file I save, and then uses that same location for the rest of the files so I end up with every single file overwriting the first. Instead I want to use the source folder of each .ai file as the destination. This doesn't seem possible without scripting.

enter image description here

Can it be done just using actions?

0

There may be a way to help your issue without scripting, but I'm not promising anything. First, observe the differences for various file types when you are recording an action Save-As or Save-a-Copy or Export or SFW..., and do a test with and without changing the file's name. Sometimes when you do not change the file's default name or when you do change the file's default name, Illustrator's behavior for overwriting the same file would be different.

If you are successful in getting it to not overwrite one file, it may be possible to achieve your goals by using batch processing and using the 'process all sub-directories' checkbox.

However, if it's not possible with just naming the files different and seeing how the action would play out- you can still get away with minimal scripting - as you would only have to create or find a very simple script to just save your SVG with current file name. Then you can take this super-simple non-batch script and include it as a menu item in your batch action! At that point, you should be able to do the exact same action process (process all sub-directories) and it should work exactly how you want!

Here's a sample script for you to try.

function test () {
    var doc = app.activeDocument;
    var newDocName = doc.name.replace(/\..+$/, "") + ".svg";
    var svgOpts = new ExportOptionsSVG;
    doc.exportFile(File(decodeURI(doc.fullName.toString()).replace(doc.name, newDocName)), ExportType.SVG, svgOpts);
};
test();
  • This is the answer. I couldn't get it working just using actions, thanks kindly for the script! – user135428 Apr 2 at 19:19
0

Anyone else looking for a solution to this, try the following code adapted from above. All opened documents will be converted to SVG and saved to the folders they were originally in.

try 
{   
    if(app.documents.length > 0) 
    {
        for(var i = app.documents.length - 1; i >= 0; i--)
        {
            var file_name               = app.documents[i].name.toString().replace(".ai", "");
            var destination             = app.documents[i].path + "/" + file_name;
            var new_path                = new File(destination);
            var options                 = new ExportOptionsSVG();
            options.coordinatePrecision = 7;
            options.embedRasterImages   = true

            app.documents[i].exportFile(new_path, ExportType.SVG, options);
            // Pass SaveOptions to suppress 'Save Changes' alert that pops up when closing a document.
            app.documents[i].close(SaveOptions.DONOTSAVECHANGES);
        }
    }
}
catch(e) 
{
    alert( e.message, "Script Alert", true);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.