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

Illustrator script to delete the layers that contain selected objects

Explorer ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

Hello

 

I have a very complex Illustrator file (architectual, from CAD) to style - and it's a bit of a mess. I need to delete lots of extraneous layers and I'd like to be able to do that by selecting several objects that appear upon those layers and run a script that will then delete all the layers that the selected items are on (and all other objects also on those layers).

 

I've searched far and wide but come across nothing so far - so please help me Adobe Ones, you're my only hope. 😉

Cheers

Rob

TOPICS
Feature request , Scripting , Third party plugins , Tools

Views

118

Translate

Translate

Report

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 1 Correct answer

Community Expert , Sep 14, 2023 Sep 14, 2023

This can be done with a simple action. Here you can download one:

 

Delete Main Layers

 

Instruction:

 

- Download and unzip the action set file.
- In the Actions palette import the action set.
- Select one or a couple of objects on a main layer.
- Run the action.

 

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

Are you talking about main layers only or about some more nested constructions?

 

Votes

Translate

Translate

Report

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 ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

Hello

 

It's just the main (top level) layers that  I'm trying to delete.

Cheers

R

Votes

Translate

Translate

Report

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 ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

This can be done with a simple action. Here you can download one:

 

Delete Main Layers

 

Instruction:

 

- Download and unzip the action set file.
- In the Actions palette import the action set.
- Select one or a couple of objects on a main layer.
- Run the action.

 

Votes

Translate

Translate

Report

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 ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

Thank you.

Votes

Translate

Translate

Report

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 ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

LATEST

@Rob.Wood I may be late to the game with your question but I think this script might accomplish what you are looking for.

// Script to Delete Layers Containing Selected Objects
(function () {
    // Check if there is an active document
    if (app.documents.length > 0) {
      // Get the active document
      var doc = app.activeDocument;
      
      // Get the selected objects
      var selectedObjects = doc.selection;
      
      // Check if there are selected objects
      if (selectedObjects.length > 0) {
        // Loop through all layers in reverse order
        for (var i = doc.layers.length - 1; i >= 0; i--) {
          var layer = doc.layers[i];
          
          // Check if any selected object is on this layer
          var deleteLayer = false;
          for (var j = 0; j < selectedObjects.length; j++) {
            if (selectedObjects[j].layer == layer) {
              deleteLayer = true;
              break;
            }
          }
          
          // If the layer should be deleted, remove it
          if (deleteLayer) {
            layer.remove();
          }
        }
        
        // Alert when the process is completed
        alert("Selected objects' layers have been deleted.");
      } else {
        // No selected objects found
        alert("No objects are currently selected.");
      }
    } else {
      // No active document found
      alert("No active document found.");
    }
  })();
  


Hope this Helps!
 

Votes

Translate

Translate

Report

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