Answered
Need help with error that never occurred in the past with this script for Illustrator 2023
When we run this script it generates an error at line 16 which is the
doc.layers.getByName(name).visible = false;
and I am not sure why this is happening. Below is the script and it is created as an action item and a specific folder is identifed to run against which then creates new files and places the in the two designated folders at the top of the script.
#target illustrator
function test(){
var folder_1 = Folder("~/Desktop/Header CAD");
var folder_2 = Folder("~/Desktop/Clean CAD");
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
function revealAllLayers(doc) {
for (var i = doc.layers.length - 1; i >= 0; i--) {
doc.layers[i].visible = true;
}
};
function hideLayer(doc, name) {
doc.layers.getByName(name).visible = false;
};
function exportMyPng(dest, doc, props) {
if(props.hasOwnProperty("antiAliasing")){
switch(props.antiAliasing){
case "ARTOPTIMIZED" : {
app.preferences.setIntegerPreference("plugin/PNGFileFormat/AntiAlias", 1);
break;
}
default : {
break;
}
}
}
var pngOpts = new ImageCaptureOptions();
pngOpts.antiAliasing = true;
for (var all in props) {
if (pngOpts.hasOwnProperty(all) && all != "antiAliasing") {
pngOpts[all] = props[all];
}
}
doc.imageCapture(File(dest + "/" + doc.name.replace(/\.\w+$/, props.extraStuff + ".png").substr(props.charsOffStart)), doc.visibleBounds, pngOpts);
};
var doc = app.activeDocument;
revealAllLayers(doc);
hideLayer(doc, "Materials");
exportMyPng(folder_1, doc, {
transparency: false,
antiAliasing: "ARTOPTIMIZED",
resolution: 300,
extraStuff: "_header",
charsOffStart: 0
});
hideLayer(doc, "Header");
hideLayer(doc, "Detail Artwork");
exportMyPng(folder_2, doc, {
transparency: false,
antiAliasing: "ARTOPTIMIZED",
resolution: 300,
extraStuff: "",
charsOffStart: -9
});
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
};
test();
