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
This can be done with a simple action. Here you can download one:
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.
Copy link to clipboard
Copied
Are you talking about main layers only or about some more nested constructions?
Copy link to clipboard
Copied
Hello
It's just the main (top level) layers that I'm trying to delete.
Cheers
R
Copy link to clipboard
Copied
This can be done with a simple action. Here you can download one:
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.
Copy link to clipboard
Copied
Thank you.
Copy link to clipboard
Copied
@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!