Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Illustrator CC Script to Auto Size Artboard and Save File name

Community Beginner ,
Jun 21, 2018 Jun 21, 2018

HI,

Not very familiar with scripting for Illustrator. Need to create a script, preferably for batches of files. Need to add small extension to artboard to files and auto add the file name and save. Is this possible? Any help would be greatly appreciated.

TOPICS
Scripting
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Engaged ,
Jun 22, 2018 Jun 22, 2018

First snippet:

Here we generate a copy of your actual AI file. Therefore we extract the file name, add an extension as you like, and save the copy on your desktop. After that it re-opens the original file.

var doc = app.activeDocument;

var original_file = doc.fullName;  // we need this to return to original file

var arr = doc.name.split(".");

var extension = "";

if (arr.length>1) extension = "." + arr.pop();

var filename = arr.join(".");

var aiSuff = '_version1.ai'; // put in any extension you like but keep suffix .ai

var name_ai = filename + aiSuff;

var export_folder = "~/Desktop"; // define the place where to save the copy

saveCopyAsAI (name_ai);

function saveCopyAsAI (nameAI) {

    var packaged_file = null;

        packaged_file = File (export_folder + "/" + nameAI);

    var save_options = new IllustratorSaveOptions();

        save_options.embedICCProfile = false;

        save_options.pdfCompatible = false

    doc.saveAs (packaged_file, save_options);

    doc.close ();

    app.open (File (original_file));

}

Next step would be:

You'll have to name your artboard, then extract the name and add them to "name_ai". If you have files with more than one artboard you'll have to define which artboard's name should be used. In case you only have 1 artboard just add:

var abName = app.activeDocument.artboards[0].name;

and change

var aiSuff = "_" + abName + ".ai";

Second snippet:

Opens a dialog where you have to choose a folder containig multiple AI files.

var dir = Folder.selectDialog("Choose folder containing .ai files");

var files = dir.getFiles("*.ai");

for(var f = 0; f < files.length; f++){

    var doc = app.open(files);

    //Your processing

    doc.close(SaveOptions.DONOTSAVECHANGES);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 25, 2018 Jul 25, 2018

HI,

Thanks for this! I have very little experience with Java. I consolidated the code you sent in Extendscript. It doesnt appear to work. Ideally we need to have this work through an action and overwrite the file in a folder. This would be a batch type action.

Any suggestions?

var doc = app.activeDocument;

var original_file = doc.fullName;  // we need this to return to original file

var arr = doc.name.split(".");

var extension = "";

if (arr.length>1) extension = "." + arr.pop();

var filename = arr.join(".");

var aiSuff = '_version1.ai'; // put in any extension you like but keep suffix .ai

var name_ai = filename + aiSuff;

var export_folder = "~/Desktop"; // define the place where to save the copy

saveCopyAsAI (name_ai);

function saveCopyAsAI (nameAI) {

    var packaged_file = null;

        packaged_file = File (export_folder + "/" + nameAI);

    var save_options = new IllustratorSaveOptions();

        save_options.embedICCProfile = false;

        save_options.pdfCompatible = false

    doc.saveAs (packaged_file, save_options);

    doc.close ();

    app.open (File (original_file));

}

var abName = app.activeDocument.artboards[0].name;

var aiSuff = "_" + abName + ".ai";

var dir = Folder.selectDialog("Choose folder containing .ai files");

var files = dir.getFiles("*.ai");

for(var f = 0; f < files.length; f++){

    var doc = app.open(files);

    //Your processing

    doc.close(SaveOptions.DONOTSAVECHANGES);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 25, 2018 Jul 25, 2018

I would have needed more clarification regarding the objective here:

Need to add small extension to artboard to files and auto add the file name and save

Is the 'small extension', like you're adding some more space to the artboard and widening it? Or are you adding a word to the artboard names. Many interpretations could emerge from every several words in this statement.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 26, 2018 Jul 26, 2018

HI,

Yes, the intent would be to add space on the bottom of the artboard, add the text for the file name to the bottom left and save over the file in the original location.

Ideally there would be 4 versions for files that are at 100, 50, 25 and 10% scale, so the text should scale accordingly.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 30, 2018 Jul 30, 2018
LATEST

Salut,

J'ai réalisé un script qui je pense correspond à ta demande :

Avant en haut et après en bas.

Pour bob.PNG

Me contacter par mail

elleere

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines