Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
2

Recording Delete Hidden Layers in an Action (Illustrator)

Engaged ,
Apr 25, 2024 Apr 25, 2024

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?

TOPICS
Bug , Feature request , How-to , Scripting , Tools
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Apr 25, 2024 Apr 25, 2024

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

...
Translate
Community Expert , Oct 15, 2024 Oct 15, 2024

Here is the download link, Lunnson:

 

Delete Layers

 

Try it out and report if it's suitable.

Translate
Adobe
Community Expert ,
Apr 25, 2024 Apr 25, 2024

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 25, 2024 Apr 25, 2024

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 25, 2024 Apr 25, 2024

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 15, 2024 Oct 15, 2024

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2024 Oct 15, 2024

Here is the download link, Lunnson:

 

Delete Layers

 

Try it out and report if it's suitable.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 15, 2024 Oct 15, 2024

Thanks a bunch! I will play around with it. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 03, 2025 Apr 03, 2025

Thank you so much for this, Kurt Gold! Not only does it allow deleting hidden layers, but also has options for Empty or Locked or Non-Printing layers too. After testing this out, the only issue I find is that it will not delete a hidden layer if it contains a linked place item in it. At least I'm guessing that is the reason it is not deleting, because if I first embed the linked image before running the script it then removes it as expected. Any ideas on how to make it also remove hidden layers that include linked items?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 03, 2025 Apr 03, 2025

Actually, now that I'm using it more, the layer that had a linked object on it DOES get deleted. But not witht he others. All the hidden layers disappear from the Layers pallette, but the one with the linked object remains — UNTIL I go to click in the pallette. Then it also disappears. Strange.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 03, 2025 Apr 03, 2025
LATEST

Thanks for reporting, RPG.

 

I tried to reproduce the behaviour you're describing, but as far as I can see I cannot replicate it. I used several linked file formats and their parent layers get deleted when they are locked or hidden.

 

Which version of Illustrator are you using? What OS?

Also (apart from possible bugs), remember that scripts in general may sometimes not work as expected when Illustrator and/or the entire machine have not been restarted for a long time.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 16, 2024 Oct 16, 2024

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();
}
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 25, 2024 Apr 25, 2024

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:

pixxxelschubser_0-1714078328420.png

 

That means:
at first: tick on: Paste remember layers

action name: Delete hidden

  • layer command: unlock all layers
  • select all
  • cut
  • layer command: all layers visible
  • unlock all
  • all visible
  • select all
  • delete
  • paste in place

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 25, 2024 Apr 25, 2024

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 25, 2024 Apr 25, 2024

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines