Skip to content

Instantly share code, notes, and snippets.

@moritzschaefer
Created August 24, 2020 15:39
Show Gist options
  • Select an option

  • Save moritzschaefer/7aa4c5a446fa85d59b9ed5066ded2bef to your computer and use it in GitHub Desktop.

Select an option

Save moritzschaefer/7aa4c5a446fa85d59b9ed5066ded2bef to your computer and use it in GitHub Desktop.

Revisions

  1. Moritz created this gist Aug 24, 2020.
    69 changes: 69 additions & 0 deletions batch_convert_to_dina4_ai.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    function resize() {
    if (app.documents.length > 0) {
    var docRef = app.activeDocument;
    if (docRef.artboards.length > 1)
    {
    alert('Need exactly one artboard');
    quit;
    }
    // Found 1 artboard
    var current = docRef.artboards[0].artboardRect;
    current[2] = current[0] + 595.2756;
    current[3] = current[1] - 841.8898;

    docRef.artboards[0].artboardRect = current;
    }
    else {
    alert('Open a document before running this script', 'Error running FitArtboardToArt.jsx');
    }
    }


    var sourceFolder = Folder("C:\\Users\\Moritz\\Syncbox\\svgs");
    var destFolder = Folder("C:\\Users\\Moritz\\Syncbox\\ais"); // optional: destFolder = Folder.selectDialog( 'Select the folder where you want to save the converted SVG files.', '~' );

    function getNewName(sourceDoc)
    {
    var ext, docName, newName, saveInFile, docName;
    docName = sourceDoc.name;
    ext = '.ai'; // new extension
    newName = "";

    for ( var i = 0 ; docName[i] != "." ; i++ )
    {
    newName += docName[i];
    }
    newName += ext; // full svg name of the file

    // Create a file object to save the svg
    saveInFile = new File( destFolder + "\\" + newName );

    return saveInFile;
    }


    if ( sourceFolder != null )
    {
    var files = new Array();
    //What kind of file in the source folder are you seeking?
    var fileType = "*.svg";
    // Get all files matching that file type
    files = sourceFolder.getFiles( fileType );

    if ( files.length > 0 )
    {
    for ( i = 0; i < files.length; i++ )
    {
    //Open a file
    var sourceDoc = app.open(files[i]);
    resize();
    app.activeDocument.saveAs(getNewName(sourceDoc));
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
    }
    alert( 'Complete' );
    }
    else
    {
    alert( 'No matching files found' );
    }