Copy link to clipboard
Copied
I have a series of Illustrator AI files, some with hidden layers that I need to delete.
I can use the Delete Hidden Layers command within the Layers panel to remove them all, manually.
However, this command is not recordable as an Action.
I can record "Unlock All Layers." (Many of my layers are also locked.) In the Actions panel, it shows as:
>Show:
Unlock All Layers
When I try to record "Delete Hidden Layers," it's recorded in the Actions panel as:
>Show:
Name:
This step of the action just creates a new Layer (and prompts me to name it).
I've also tried "Insert Menu Item" from the Actions panel, but it appears menu items from panels are not included in that option.
Is it really just impossible to perform this menu function without resorting to writing code?
Why are so many of Illustrator's commands and menu items not actionable?
You are right that the implementation of the Delete Hidden Layers command in the Actions palette is nonsense, just as the command itself (strictly speaking) because it also deletes objects and not just layers.
Currently, you'd indeed have to resort to creating a script for that task. I've created one that does delete empty, locked, hidden or non-printing main layers and sublayers. Currently it does not delete hidden objects. Let me know if that may help you and I'll post a download link.
As
...Copy link to clipboard
Copied
You are right that the implementation of the Delete Hidden Layers command in the Actions palette is nonsense, just as the command itself (strictly speaking) because it also deletes objects and not just layers.
Currently, you'd indeed have to resort to creating a script for that task. I've created one that does delete empty, locked, hidden or non-printing main layers and sublayers. Currently it does not delete hidden objects. Let me know if that may help you and I'll post a download link.
As for your question: Why are so many of Illustrator's commands and menu items not actionable?
The answer is pretty simple and disappointing: It's because for many years Adobe has lost sight of implementing many commands as actionable commands.
About ten years ago, there was an official announcement indicating that the entire actions architecture was going to be revamped. Unfortunately, it was kicked into the long grass.
Copy link to clipboard
Copied
Thanks, Kurt, I was hoping to avoid scripting. (I need something that's easy to maintain and adapt — and also deploy to a user base that doesn't have admin rights to install things like scripts into the application folder.)
I've seen a few scripts for doing this — and for the record, I'm OK with deleting anything that isn't visible. The adjustments I'm making for color (like making them grayscale) require selecting them first, and I can't do that if they're not visible. This leaves objects in a state I don't want (e.g. color) still in the file.
Illustrator is like InDesign, in that you have multiple objects inside layers, each with their own visibility. Photoshop's layers are all individual objects.
Photoshop's command to Delete Hidden Layers works differently, in that you can have a layer group that has the visibility turned off, while objects inside the group still have their individual visibility set to on. (The layers are invisible, because the parent layer group is invisible.)
I have a script that selects all the visible layers in Photoshop. It selects layers that are not visible because the layer attributes themselves are set to "on" while the layer group they're in is set to "off." So while the script technically doesn't work (selecting invisible layers) the Delete Hidden Layers command in Photoshop will delete these layers, because it deletes hidden layer groups — even if the contents of those groups are still set to "visible."
Which is the correct order of operations in that scenario? It's subject to the objective, I guess.
Edit: oh, and for the record, "Delete Hidden Layers" in Photoshop is both recordable and insertable with the "Insert Menu Item" command in the panel.
Copy link to clipboard
Copied
Thanks for the clarification.
If it has to be an action or if it is just the preferable approach, it may be done in some way.
Can you share a couple of Illustrator files you're going to process with an action that would delete anything that is invisible?
Copy link to clipboard
Copied
I would love to play around with that script if it's available. I was trying to do the same thing with creating an action that uses the delete hidden layers with no success. However, I need to keep locked layers intact.
Thank you!
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks a bunch! I will play around with it.
Copy link to clipboard
Copied
just a follow-up: I have indeed resorted to using a script. I have one (given to me by someone who found it in another forum) that deletes any layer, layer group, or items that are turned off, locked or unlocked.
#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();
}
}
Copy link to clipboard
Copied
The problem can be partially, though unfortunately not completely, circumvented.
(Empty layers remain in the document, but all hidden objects are deleted.)
You can try to go the opposite way:
That means:
at first: tick on: Paste remember layers
action name: Delete hidden
Copy link to clipboard
Copied
that's a very interesting workaround. The simplest solutions are usually best.
Here's my only concern (and one that would need testing): if two items, same layer or different, were interacting with each other with effects or blending modes (clipping masks, etc.), would cutting them out of the document and then pasting them back in preserve all of that? Would those interactions between objects remain through a cut and paste?
Copy link to clipboard
Copied
Considering all possible special cases was one reason why I asked for some Illustrator sample files, so one can inspect what action approaches are realistic or what else has to be done to make them work.