Highlighted

Automating Bach

Community Beginner ,
May 14, 2019

Copy link to clipboard

Copied

Hello everyone!

Im learning and trying to make work one script. I just copy one from B. Scott​ (THANK YOU FOR SHARING), but I have some issues.

Im using Illustrator CC last version 23.0.3 and I need 2 small changes, but I don't know where is the problem (I put them in red).

1. Don't create me new folders, they ask me always, but they shouldn't do it

2. Also they ask me always about the name, and they should do it alone too. (the idea is to give illustrator a LOT of archives and leave alone a long time)

In other way I want to change somethings about layers, but I think I can do it alone!


THANK YOU!

#target Illustrator 

 

app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; 

 

var dir = Folder.selectDialog("Select folder containing .ai files for processing."); 

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

 

var pdfOption1 = 'Print pdf'; // <--- in here put the name of your PDF settings for EPSON 

var pdfOption2 = 'Print pdf'; // <--- in here put the name of your PDF settings for printing 

var pdfOption3 = '[Illustrator Default]'; // <--- in here put the name of your PDF settings for ICUT 

 

var pdfFolder1 = '/epson'; 

var pdfFolder2 = '/print%20files'; 

var pdfFolder3 = '/icut'; 

 

var pdfSuff1 = '_e.pdf'; // Suffix for  EPSON PDF 

var pdfSuff2 = '_print.pdf'; // Suffix print PDF 

var pdfSuff3 = '_icut.pdf'; // Suffix ICUT PDF 

 

function doesLayerExist(layers, name) { 

    for (i=0; i<layers.length; i++) { 

        if (layers.name==name) return true; 

    } 

    return false; 

 

function delete_hidden () { 

    var idoc = app.activeDocument; 

    for (i = idoc.pageItems.length-1; i >= 0; i--){ 

          if (idoc.pageItems.hidden == true){ 

                idoc.pageItems.remove() 

              } 

            } 

 

function delete_hidden_layers () { 

    var myDoc=app.activeDocument; 

    var layerCount=myDoc.layers.length; 

        for (var ii = layerCount - 1; ii >= 0; ii--) { 

        var currentLayer = myDoc.layers[ii]; 

            currentLayer.locked = false; 

        var subCount = currentLayer.layers.length; 

        for (var ss = subCount -1; ss >= 0; ss--){ 

        var subLayer = currentLayer.layers[ss]; 

        subLayer.locked = false; 

        if (subLayer.visible == false){ 

            subLayer.visible = true; 

            if (subLayer.name != 'typosafe') { 

                subLayer.remove()} 

            else { 

                subLayer.visible = false}; 

            } 

        } 

    if (currentLayer.visible == false){ 

        currentLayer.visible = true; 

        if (currentLayer.name != 'typosafe') { 

                currentLayer.remove()} 

            else { 

                currentLayer.visible = false}; 

        } 

    } 

 

function hide_layer (hideme) { 

    var doc = app.activeDocument; 

    var myLayers = doc.layers; 

    try { 

        HideLayer = myLayers.getByName (hideme); 

        HideLayer.visible = false; 

        redraw(); 

        } 

    catch (e) {} 

 

function saveCopyAsPDF (setPDF, placePDF, namePDF) { 

        var doc = app.activeDocument; 

        

        var original_file = doc.fullName; 

        

        var home = original_file.parent; // here we get the full path to the directory containing your AI file 

        var export_folder = export_folder = home + placePDF; // there we want to create a subfolder 

 

 

        

        var options = new PDFSaveOptions (); 

            options.PDFPreset = setPDF; 

            options.viewAfterSaving = false; 

        var targetFile = null; 

            targetFile = app.activeDocument.name.toString().replace(".ai", namePDF); 

            alert (export_folder + "/" + targetFile); // alert for testing save locations 

        doc.saveAs(new File (export_folder + "/UNO" + targetFile), options); // new save code with export folder directory, a slash, and the appended filename 

        doc.close (); 

        } 

 

function fontvect (){ 

while (doc.textFrames.length != 0) { 

        doc.textFrames[0].createOutline(); 

        } 

    } 

 

function hide_all_but_cut () { 

    var myDoc = app.activeDocument; 

    var layerCount = myDoc.layers.length; 

    var layerCount2 = myDoc.layers.length; 

 

 

 

    for (var ii = layerCount - 1; ii >= 0; ii--) { 

        var currentLayer = myDoc.layers[ii]; 

            currentLayer.locked = false; 

            currentLayer.visible = false; 

        }; 

 

    for (var i = layerCount2 - 1; i >= 0; i--) { 

        var currentLayer2 = myDoc.layers

        if (currentLayer2.name == "Outside Cut") {currentLayer2.visible = true}; 

        else if (currentLayer2.name == "Holes-Inside Cut") {currentLayer2.visible = true}; 

        else if (currentLayer2.name == "Score") {currentLayer2.visible = true}; 

else if (currentLayer2.name == "regmarks") {currentLayer2.visible = true}; 

        else {currentLayer2.visible = false}; 

        }; 

        } 

 

 

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

        var doc = app.open(files); 

        var original_file = doc.fullName; 

        delete_hidden_layers (); // delete all hidden layers 

        delete_hidden (); // delete all hidden objects 

        fontvect (); // outline fonts 

        if (!doc.saved) doc.save(); // base file cleaned up, now save it  

        

        splitemup (doc); 

        }; 

 

function splitemup (doc) { 

 

var doc = app.activeDocument; 

 

if (doesLayerExist(app.activeDocument.layers, "Outside Cut") || doesLayerExist(app.activeDocument.layers, "Holes-Inside Cut") || doesLayerExist(app.activeDocument.layers, "Score")){ 

saveCopyAsPDF (pdfOption1, pdfFolder1, pdfSuff1); // save as PDF for EPSON 

 

app.open (File (original_file)); // return to original file 

 

hide_layer ("Outside Cut"); 

hide_layer ("Holes-Inside Cut"); 

hide_layer ("Score"); 

    

saveCopyAsPDF (pdfOption2, pdfFolder2, pdfSuff2); // save as PDF for Print 

app.open (File (original_file)); // return to original file 

 

 

if (doesLayerExist(app.activeDocument.layers, "regmarks")){ 

    

hide_all_but_cut (); 

delete_hidden_layers (); 

      

saveCopyAsPDF (pdfOption3, pdfFolder3, pdfSuff3); // save as PDF for ICUT 

} else { 

    activeDocument.close(); 

    } 

}; 

TOPICS
Scripting

Views

677

Likes

Translate

Translate

Report

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

Automating Bach

Community Beginner ,
May 14, 2019

Copy link to clipboard

Copied

Hello everyone!

Im learning and trying to make work one script. I just copy one from B. Scott​ (THANK YOU FOR SHARING), but I have some issues.

Im using Illustrator CC last version 23.0.3 and I need 2 small changes, but I don't know where is the problem (I put them in red).

1. Don't create me new folders, they ask me always, but they shouldn't do it

2. Also they ask me always about the name, and they should do it alone too. (the idea is to give illustrator a LOT of archives and leave alone a long time)

In other way I want to change somethings about layers, but I think I can do it alone!


THANK YOU!

#target Illustrator 

 

app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; 

 

var dir = Folder.selectDialog("Select folder containing .ai files for processing."); 

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

 

var pdfOption1 = 'Print pdf'; // <--- in here put the name of your PDF settings for EPSON 

var pdfOption2 = 'Print pdf'; // <--- in here put the name of your PDF settings for printing 

var pdfOption3 = '[Illustrator Default]'; // <--- in here put the name of your PDF settings for ICUT 

 

var pdfFolder1 = '/epson'; 

var pdfFolder2 = '/print%20files'; 

var pdfFolder3 = '/icut'; 

 

var pdfSuff1 = '_e.pdf'; // Suffix for  EPSON PDF 

var pdfSuff2 = '_print.pdf'; // Suffix print PDF 

var pdfSuff3 = '_icut.pdf'; // Suffix ICUT PDF 

 

function doesLayerExist(layers, name) { 

    for (i=0; i<layers.length; i++) { 

        if (layers.name==name) return true; 

    } 

    return false; 

 

function delete_hidden () { 

    var idoc = app.activeDocument; 

    for (i = idoc.pageItems.length-1; i >= 0; i--){ 

          if (idoc.pageItems.hidden == true){ 

                idoc.pageItems.remove() 

              } 

            } 

 

function delete_hidden_layers () { 

    var myDoc=app.activeDocument; 

    var layerCount=myDoc.layers.length; 

        for (var ii = layerCount - 1; ii >= 0; ii--) { 

        var currentLayer = myDoc.layers[ii]; 

            currentLayer.locked = false; 

        var subCount = currentLayer.layers.length; 

        for (var ss = subCount -1; ss >= 0; ss--){ 

        var subLayer = currentLayer.layers[ss]; 

        subLayer.locked = false; 

        if (subLayer.visible == false){ 

            subLayer.visible = true; 

            if (subLayer.name != 'typosafe') { 

                subLayer.remove()} 

            else { 

                subLayer.visible = false}; 

            } 

        } 

    if (currentLayer.visible == false){ 

        currentLayer.visible = true; 

        if (currentLayer.name != 'typosafe') { 

                currentLayer.remove()} 

            else { 

                currentLayer.visible = false}; 

        } 

    } 

 

function hide_layer (hideme) { 

    var doc = app.activeDocument; 

    var myLayers = doc.layers; 

    try { 

        HideLayer = myLayers.getByName (hideme); 

        HideLayer.visible = false; 

        redraw(); 

        } 

    catch (e) {} 

 

function saveCopyAsPDF (setPDF, placePDF, namePDF) { 

        var doc = app.activeDocument; 

        

        var original_file = doc.fullName; 

        

        var home = original_file.parent; // here we get the full path to the directory containing your AI file 

        var export_folder = export_folder = home + placePDF; // there we want to create a subfolder 

 

 

        

        var options = new PDFSaveOptions (); 

            options.PDFPreset = setPDF; 

            options.viewAfterSaving = false; 

        var targetFile = null; 

            targetFile = app.activeDocument.name.toString().replace(".ai", namePDF); 

            alert (export_folder + "/" + targetFile); // alert for testing save locations 

        doc.saveAs(new File (export_folder + "/UNO" + targetFile), options); // new save code with export folder directory, a slash, and the appended filename 

        doc.close (); 

        } 

 

function fontvect (){ 

while (doc.textFrames.length != 0) { 

        doc.textFrames[0].createOutline(); 

        } 

    } 

 

function hide_all_but_cut () { 

    var myDoc = app.activeDocument; 

    var layerCount = myDoc.layers.length; 

    var layerCount2 = myDoc.layers.length; 

 

 

 

    for (var ii = layerCount - 1; ii >= 0; ii--) { 

        var currentLayer = myDoc.layers[ii]; 

            currentLayer.locked = false; 

            currentLayer.visible = false; 

        }; 

 

    for (var i = layerCount2 - 1; i >= 0; i--) { 

        var currentLayer2 = myDoc.layers

        if (currentLayer2.name == "Outside Cut") {currentLayer2.visible = true}; 

        else if (currentLayer2.name == "Holes-Inside Cut") {currentLayer2.visible = true}; 

        else if (currentLayer2.name == "Score") {currentLayer2.visible = true}; 

else if (currentLayer2.name == "regmarks") {currentLayer2.visible = true}; 

        else {currentLayer2.visible = false}; 

        }; 

        } 

 

 

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

        var doc = app.open(files); 

        var original_file = doc.fullName; 

        delete_hidden_layers (); // delete all hidden layers 

        delete_hidden (); // delete all hidden objects 

        fontvect (); // outline fonts 

        if (!doc.saved) doc.save(); // base file cleaned up, now save it  

        

        splitemup (doc); 

        }; 

 

function splitemup (doc) { 

 

var doc = app.activeDocument; 

 

if (doesLayerExist(app.activeDocument.layers, "Outside Cut") || doesLayerExist(app.activeDocument.layers, "Holes-Inside Cut") || doesLayerExist(app.activeDocument.layers, "Score")){ 

saveCopyAsPDF (pdfOption1, pdfFolder1, pdfSuff1); // save as PDF for EPSON 

 

app.open (File (original_file)); // return to original file 

 

hide_layer ("Outside Cut"); 

hide_layer ("Holes-Inside Cut"); 

hide_layer ("Score"); 

    

saveCopyAsPDF (pdfOption2, pdfFolder2, pdfSuff2); // save as PDF for Print 

app.open (File (original_file)); // return to original file 

 

 

if (doesLayerExist(app.activeDocument.layers, "regmarks")){ 

    

hide_all_but_cut (); 

delete_hidden_layers (); 

      

saveCopyAsPDF (pdfOption3, pdfFolder3, pdfSuff3); // save as PDF for ICUT 

} else { 

    activeDocument.close(); 

    } 

}; 

TOPICS
Scripting

Views

678

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 14, 2019 0
Explorer ,
May 14, 2019

Copy link to clipboard

Copied

I can't offer any insight, as the code here was mostly cobbled together by me after receiving substantial help. In my workflow I have a blank job folder that contains folders already. I place the illustrator files to be batched in this directory, and the script looks for the specifically named sub-folders. I don't know how to make the script create its own folders at this time. If you create a folder with these subfolders and process your files from here, the script will work. Keep in mind that it is also dependent on having very specifically named layers in your document as well.Screen Shot 2019-05-14 at 10.11.42 AM.png

You can change the names of these folders in the script if need be, as long as they are present in the directory that your illustrator file is in, they should be processed correctly.

I do know that it will ask for the names when it cannot find those folders.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 14, 2019 0
Community Beginner ,
May 14, 2019

Copy link to clipboard

Copied

Thank you B.Scott. This was the problem, I didn't have that folders...

Someone knows to create also their own folder for their archive?

Thank you so much. You are going to avoid wasting a loot of time

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 14, 2019 0
Adobe Community Professional ,
May 14, 2019

Copy link to clipboard

Copied

you can create the folders if they don't exists

     if (myFolder.exists) {

          do your thing

     }

     else {

          myFolder.create();

     }

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 14, 2019 2
Contributor ,
May 16, 2019

Copy link to clipboard

Copied

Hello

Here is the updated code. I have marked code as BOLD which I have updated.
Hope this help you

# target Illustrator

app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

var dir = Folder.selectDialog("Select folder containing .ai files for processing.");

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

var pdfOption1 = 'Print pdf'; // <--- in here put the name of your PDF settings for EPSON

var pdfOption2 = 'Print pdf'; // <--- in here put the name of your PDF settings for printing

var pdfOption3 = '[Illustrator Default]'; // <--- in here put the name of your PDF settings for ICUT

var pdfFolder1 = '/epson';

var pdfFolder2 = '/print%20files';

var pdfFolder3 = '/icut';

var pdfSuff1 = '_e.pdf'; // Suffix for  EPSON PDF

var pdfSuff2 = '_print.pdf'; // Suffix print PDF

var pdfSuff3 = '_icut.pdf'; // Suffix ICUT PDF

function doesLayerExist(layers, name) {

     for (i = 0; i < layers.length; i++) {

          if (layers.name == name) return true;

     }

     return false;

}

function delete_hidden() {

var idoc = app.activeDocument;

for (i = idoc.pageItems.length - 1; i >= 0; i--) {

if (idoc.pageItems.hidden == true) {

idoc.pageItems.remove()

}

}

}

function delete_hidden_layers() {

var myDoc = app.activeDocument;

var layerCount = myDoc.layers.length;

for (var ii = layerCount - 1; ii >= 0; ii--) {

var currentLayer = myDoc.layers[ii];

currentLayer.locked = false;

var subCount = currentLayer.layers.length;

for (var ss = subCount - 1; ss >= 0; ss--) {

var subLayer = currentLayer.layers[ss];

subLayer.locked = false;

if (subLayer.visible == false) {

subLayer.visible = true;

if (subLayer.name != 'typosafe') {

subLayer.remove()

} else {

subLayer.visible = false

};

}

}

if (currentLayer.visible == false) {

currentLayer.visible = true;

if (currentLayer.name != 'typosafe') {

currentLayer.remove()

} else {

currentLayer.visible = false

};

}

}

}

function hide_layer(hideme) {

var doc = app.activeDocument;

var myLayers = doc.layers;

try {

HideLayer = myLayers.getByName(hideme);

HideLayer.visible = false;

redraw();

} catch (e) {}

}

function saveCopyAsPDF(setPDF, placePDF, namePDF) {

var doc = app.activeDocument;

var original_file = doc.fullName;

var home = original_file.parent; // here we get the full path to the directory containing your AI file

var export_folder = export_folder = home + placePDF; // there we want to create a subfolder

var options = new PDFSaveOptions();

options.PDFPreset = setPDF;

options.viewAfterSaving = false;

var targetFile = null;

targetFile = app.activeDocument.name.toString().replace(".ai", namePDF);

alert(export_folder + "/" + targetFile); // alert for testing save locations

var newFolder = new Folder(export_folder + "/UNO");

if (!newFolder.exists)

newFolder.create();

doc.saveAs(new File(newFolder + "/" + targetFile), options); // new save code with export folder directory, a slash, and the appended filename

doc.close();

}

function fontvect() {

while (doc.textFrames.length != 0) {

doc.textFrames[0].createOutline();

}

}

function hide_all_but_cut() {

var myDoc = app.activeDocument;

var layerCount = myDoc.layers.length;

var layerCount2 = myDoc.layers.length;

for (var ii = layerCount - 1; ii >= 0; ii--) {

var currentLayer = myDoc.layers[ii];

currentLayer.locked = false;

currentLayer.visible = false;

};

for (var i = layerCount2 - 1; i >= 0; i--) {

var currentLayer2 = myDoc.layers;

if (currentLayer2.name == "Outside Cut") {

currentLayer2.visible = true

};

else if (currentLayer2.name == "Holes-Inside Cut") {

currentLayer2.visible = true

};

else if (currentLayer2.name == "Score") {

currentLayer2.visible = true

};

else if (currentLayer2.name == "regmarks") {

currentLayer2.visible = true

};

else {

currentLayer2.visible = false

};

};

}

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

var doc = app.open(files);

var original_file = doc.fullName;

delete_hidden_layers(); // delete all hidden layers

delete_hidden(); // delete all hidden objects

fontvect(); // outline fonts

if (!doc.saved) doc.save(); // base file cleaned up, now save it 

splitemup(doc);

};

function splitemup(doc) {

var doc = app.activeDocument;

if (doesLayerExist(app.activeDocument.layers, "Outside Cut") || doesLayerExist(app.activeDocument.layers, "Holes-Inside Cut") || doesLayerExist(app.activeDocument.layers, "Score")) {

saveCopyAsPDF(pdfOption1, pdfFolder1, pdfSuff1); // save as PDF for EPSON

app.open(File(original_file)); // return to original file

hide_layer("Outside Cut");

hide_layer("Holes-Inside Cut");

hide_layer("Score");

}

saveCopyAsPDF(pdfOption2, pdfFolder2, pdfSuff2); // save as PDF for Print

app.open(File(original_file)); // return to original file

if (doesLayerExist(app.activeDocument.layers, "regmarks")) {

hide_all_but_cut();

delete_hidden_layers();

saveCopyAsPDF(pdfOption3, pdfFolder3, pdfSuff3); // save as PDF for ICUT

} else {

activeDocument.close();

}

};

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 16, 2019 0
Community Beginner ,
Jun 10, 2019

Copy link to clipboard

Copied

Thank you very much Charur,

Its possible to create a new folder with the doc name? Im trying with this, but don't works.

var newFolder = new Folder(export_folder + "/app.activeDocument.name");

THANK YOU!!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 10, 2019 1
Community Beginner ,
Apr 21, 2020

Copy link to clipboard

Copied

Hi Leticia
Thank you very much for your work, it was so helpfull for me.
I want to create automatically this folders as you say, but i cant do it and i dont know how to do it.

 

I want to put a lot of .ai documents and exports them in their folder. Do you know how to do it?


Example:

 

Original folder:

1.ai

2.ai

 

What i want the export with automated creations of folders. I need to take the name of the .ai and put it in the first folder

 

1 /subfolder 1/ subsubfolder1/1.pdf

1 /subfolder 1/ subsubfolder2/1.png

1 /subfolder 2/ subsubfolder1/1.jpeg

1 /subfolder 2/ subsubfolder2/1.ai

 

2 /subfolder 1/ subsubfolder1/2.pdf

2 /subfolder 1/ subsubfolder2/2.png

2 /subfolder 2/ subsubfolder1/2.jpeg

2 /subfolder 2/ subsubfolder2/2.ai

 

If somebody can help me i will apreciate it a lot!!

 

THANK YOU!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 21, 2020 0
Adobe Community Professional ,
May 15, 2020

Copy link to clipboard

Copied

Hi,

Replace the line in the above script

var newFolder = new Folder(export_folder + "/UNO");

with following line

var newFolder = new Folder(export_folder + "/" + doc.name.replace('.ai',''));

 

to create the folder with name of the document. doc.name.replace('.ai', '') will give you the name of the active document.

 

Thanks.

 

Best regards

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 15, 2020 1