Adobe Illustrator Javascript and Unique Name Prefixes

Post Reply
mwinker
Member
Posts: 37
Joined: Wed Dec 22, 2010 2:36 am

Adobe Illustrator Javascript and Unique Name Prefixes

Post by mwinker »

I'm working on a new flow for certain design jobs that we're working to automate. A PDF or layered AI file is opened in Illustrator and a java script is run that saves out each of 7 layers as a separate pdf file. Because the file is already running in PowerSwitch, it already has a unique name prefix. Most (but oddly enough not all) of the new layers get a second unique name prefix. After being manipulated and arriving in their final respective folders, some files retain the original unique name prefix and some do not. Each of the final folders is set to strip the unique name and to overwrite duplicate files.



I'm thinking If my script could be adjusted so that I save only the original file name plus the layer name on each saved layer, I could eliminate that problem of the second unique name prefix.



I currently know very little scripting. I found this one online and was able to modify it enough to get it to use my output style and a preferred folder in the flow. Anyone want to take a stab at what I should change?

The script follows:







#target illustrator

 

var docRef = app.activeDocument;

 

with (docRef) {

var docName = baseName(name)

var pdfOptions = new PDFSaveOptions();

pdfOptions.pDFPreset = 'WilliamArthur';

// Turn all layers off

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

layers.visible = false;

}

// Turn each layer on

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

if (i == 0) {

layers.visible = true;

redraw();

var layerName = layers.name;

var saveAsPath = new File('Macintosh HD 2/POWERSWITCH DESIGN/DESIGN WORKFLOW/LAYERS/' + docName + '_' + layerName + '.pdf')

saveAs(saveAsPath, pdfOptions);

} else {

layers[i-1].visible = false;

layers.visible = true;

redraw();

var layerName = layers.name;

var saveAsPath = new File('Macintosh HD 2/POWERSWITCH DESIGN/DESIGN WORKFLOW/LAYERS/' + docName + '_' + layerName + '.pdf')

saveAs(saveAsPath, pdfOptions);

}

}

//close(SaveOptions.DONOTSAVECHANGES);

}

 

function baseName(fileName) {

var nameString = '';

var extOffset = fileName.lastIndexOf('.');

if (extOffset == -1) {

nameString = fileName;

} else {

nameString = fileName.substr(0, extOffset);

}

return nameString;

}
reprokaiser
Newbie
Posts: 16
Joined: Mon Apr 04, 2011 3:56 pm

Adobe Illustrator Javascript and Unique Name Prefixes

Post by reprokaiser »

Hi,



you should use the variables provided by Switch. This is because Illustrator doesn't really 'know' that it's driven by another application, so it behaves like an ordinary desktop software.



Please see the Switch documentation about Javascript for Adobe applications.



Review your whole code like this:



var docRef = app.activeDocument; <---- you should change to: var docRef = $doc;



with (docRef) {

var docName = baseName(name) <---- you should change to:var docName = $filename;



... and so on. This way the output might be much more consistent.



Hope this helps.



Peter
mwinker
Member
Posts: 37
Joined: Wed Dec 22, 2010 2:36 am

Adobe Illustrator Javascript and Unique Name Prefixes

Post by mwinker »

Thanks, I'll try that when I get a chance. I'm also trying the option of having our Design department save a layered pdf directly out of Illustrator. This keeps fonts and links more stable. Separating the layers to individual files is a bit tricky so far using pitstop actions.
Post Reply