At the request of Eva Healy I modified Jongware’s script to handle Illustrator files.
I also added some detailed instructions inside so even the ungeeky among us can manipulate what layers to show.
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Show/Hide Layers - Illustrator");
function Main()
{
var page, placedFile, links, layer, i, j, k,
doc = app.activeDocument;
pages = doc.pages;
var checklist = [];
var layernames = [ "red", "blue", "green", "silver"];
/* -------------------------------------------------------------------------------------------------------
ABOVE IS WHERE YOU ALTER THE LAYER NAMES:
After the words "var layernames" there's an opening square bracket , then some sets of text enclosed in quotes sperated by commas, and at the end, a closing square bracket.
Delete all of the text and the commas separating it, and in its place put in any layers that you want.
For example: If you have three layers, 'red', 'green' and 'silver', then in the brackets put in each layer enclosed in quotes and seperated by a comma, as such: ["red", "green", "silver"].
Make sure they are all double-quotes, not single quotes, and make sure they are 'straight' quotes not 'smart' quotes.
To ensure that it's properly formatted, only edit the script in a generic text editor (such as Notepad on Windows, or Text Wrangler on Mac).
DO NOT use a word-proccesing program such as MS Word or InDesign, as that will add formatting to the script and it will not work properly.
------------------------------------------------------------------------------------------------------- */
var ilDialog = app.dialogs.add({name:"Image Layers on/off", canCancel:true});
with (ilDialog)
{
with(dialogColumns.add())
{
with(dialogRows.add())
{
staticTexts.add ({staticLabel:"Check to show, uncheck to hide"});
for (i=0; i<layernames.length; i++)
{
with(dialogRows.add())
checklist.push (checkboxControls.add({staticLabel:layernames[i], checkedState:false}));
}
}
}
}
var numChanges = 0;
var imageChange;
if (ilDialog.show() == true)
{
links = doc.links;
for (i = links.length-1; i>=0; i--)
{
placedFile = links[i].parent;
// show the internal type of this image:
//alert (placedFile.constructor.name+" / "+placedFile.itemLink.linkType);
if (placedFile.constructor.name == "PDF" && placedFile.itemLink != null && placedFile.itemLink.linkType == "Adobe Portable Document Format (PDF)")
{
imageChange = false;
for (k=0; k<layernames.length; k++)
{
layer = links[i].parent.graphicLayerOptions.graphicLayers.item(layernames[k]);
if (layer.isValid && layer.currentVisibility != checklist[k].checkedState)
{
layer.currentVisibility = checklist[k].checkedState;
imageChange = true;
}
}
if (imageChange)
numChanges++;
}
}
alert("Done, made changes in "+numChanges+" images");
} else
{
ilDialog.destroy();
}
}