How to delete all hidden layers at once?

Is it possible to delete all hidden layers in Illustrator at once and how would I do this?

Answer

Here’s a script to delete all layers.

#target illustrator
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;
    if (currentLayer.visible == false){
        currentLayer.visible = true;
        currentLayer.remove();
        }
    }

Note that this will not work on any hidden layer that is locked or where the group is locked that it is inside.

To install the script, just copy the code into a notepad and save it as all files and with the filename delete_hidden_layers.jsx.

Then drop a copy of that into your scripts folder. It can be found under

C:\Program Files\Adobe\Adobe Illustrator [YOUR VERSION]\Presets\en_[YOUR LANGUAGE]\Scripts

OR

C:\Program Filesx86\Adobe\Adobe Illustrator[YOURVERSION]\Presets\en_[YOUR LANGUAGE]\Scripts

Interestingly enough Photoshop seems to have this feature built into its functionality.

enter image description here

Attribution
Source : Link , Question Author : KFifa , Answer Author : Ovaryraptor

Leave a Comment