1

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

  • 3
    I'm voting to close this question as off-topic because it's merely a yes or no question: – Scott Jun 6 '18 at 13:46
5

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

  • This script looks like it will unlock all layers in the document, which may not be desirable. Why not move the unlocking inside the if block to make sure it’s only hidden layers? – Janus Bahs Jacquet Jun 9 '18 at 14:41
1

No. The default installation of Illustrator provides no mechanism to delete layers other than manual deletion.

You may be able to use a third party script.

1

Here a script to download, similar to Ovaryraptor's, and tested as shown in this GIF:

hiddenlayers

Script:

#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;
    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;
            subLayer.remove();
            }
        }
    if (currentLayer.visible == false){
        currentLayer.visible = true;
        currentLayer.remove();
        }
    }
  • Instead of adding a download link you should add the script itself to your answer. It's short enough and we don't have to worry about that link dying one day and invalidating your answer. – Luciano Jun 10 '18 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.