Skip to main content
Participating Frequently
July 14, 2011
Answered

Release to Layers but retain layer names

  • July 14, 2011
  • 8 replies
  • 28540 views

I am unable to find a script that will do this. The default application functionality is really frustrating how it just slaps a generic "Layer 1", "Layer 2" layer name on the new layers. I would rather have the name of the sublayer become the name of the new layer. Has anyone seen a script anywhere that does this?

Correct answer Peter33375105jutd

Got it working. Here's code:

var idoc = app.activeDocument;

var ilayer = idoc.activeLayer;

for (i=0; i<ilayer.layers.length; i++)

    {
        var sublayer = ilayer.layers[i];
		  
		try {
			sublayer.name = sublayer.pageItems[0].name;
		}
		catch(err) {
			try {sublayer.name = sublayer.layers[0].name;
			}
			catch(err) {
				alert(err);
			}
		}
    }

 

8 replies

New Participant
December 14, 2024

Hello, I tried to apply this script and I can´t :C

Larry G. Schneider
Adobe Expert
December 14, 2024

If you're on a Mac and using Text Edit please make sure you have set the save format as Plain Text. The line shown indicates the file was saved as a Rich Text file.

New Participant
April 25, 2024

If anyone is out there still having the 1302 error, editing the code like this worked for me. It had to do with the type of layer inside my layers, if that makes sense. I just removed pageItems. Here's the edit:

var idoc = app.activeDocument;

var ilayer = idoc.activeLayer;

for (i=0; i<ilayer.layers.length; i++)

     {

          var sublayer = ilayer.layers[i];

          sublayer.name = sublayer[0].name;

     }

 

New Participant
April 25, 2024

Well it worked for some of my layers. I edited the code further so that it tries both types and if it doesn't work it just skips them. @CarlosCanto sorry to bother you. Any ideas?

var idoc = app.activeDocument;

var ilayer = idoc.activeLayer;

for (i=0; i<ilayer.layers.length; i++)

    {
        var sublayer = ilayer.layers[i];
		  
		try {
			sublayer.name = sublayer.pageItems[0].name;
		}
		catch(err) {
			try {
				sublayer.name = sublayer[0].name;
			}
			catch(err) {
				// pass
			}
		}
    }

 

Peter33375105jutdCorrect answer
New Participant
April 25, 2024

Got it working. Here's code:

var idoc = app.activeDocument;

var ilayer = idoc.activeLayer;

for (i=0; i<ilayer.layers.length; i++)

    {
        var sublayer = ilayer.layers[i];
		  
		try {
			sublayer.name = sublayer.pageItems[0].name;
		}
		catch(err) {
			try {sublayer.name = sublayer.layers[0].name;
			}
			catch(err) {
				alert(err);
			}
		}
    }

 

Participating Frequently
February 8, 2024

Many, many years later, amazing, thanks Carlos!

New Participant
April 25, 2024

It's crazy that this is still an issue, but also, thanks from me, Carlos! And thanks, Simon, for mentioning the "rich text" issue; it helped me a lot. 🙂

gmmapns
Participating Frequently
November 20, 2023

Hey, 

Can anyone help me with this script please? Im following the steps but nothing happens or I get an error. Do I have to select the layers in a specific way to apply the script? Thanks!

CarlosCanto
Adobe Expert
November 20, 2023

what's the error message you're getting? post an image of your layers panel expanded

gmmapns
Participating Frequently
November 21, 2023

Hey Carlos,

Firstly, thanks for coming back to me.

See attached the picture of my layers, "Hada Nadal CAMBIO" is the one im trying to use the script on. 

If I "release to layers (seq)" and click the script nothing happens.

If I "release to layers (seq)" and select the group layer and click on the script, i get the error attached

New Participant
July 4, 2023

I've edited Carlos's script so it sequentually names the sublayes (i.e "Item 1", "Item 2" etc).

 

To iterate, you need to run the "Release To Layers (Sequence)" option in the layers menu, then run this script on the parent layer:

var idoc = app.activeDocument;
var ilayer = idoc.activeLayer;

// Get the name of the top-most layer
var topLayerName = ilayer.name;

// Loop through the sublayers and rename them sequentially
for (var i = 0; i < ilayer.layers.length; i++) {
var sublayer = ilayer.layers[i];

// Create the new name using the top layer name and sequence number
var newLayerName = topLayerName + " " + (i + 1);

// Set the new name for the sublayer
sublayer.name = newLayerName;
}

Participating Frequently
August 1, 2023

Still not working for me.

 

Step 1 - release to layers (sequence)

Step 2 - run this new updated version of the script

Step 3 - cry (see screen shot of sadness)

Step 4 - rename all these little bits by hand

 

And yes, all of my layer bits have a named item in them (see screen shot where I twirled 2 open).

CarlosCanto
Adobe Expert
August 2, 2023

Hello Claire, let's try to take care of these two steps

Step 3 - cry (see screen shot of sadness)

Step 4 - rename all these little bits by hand

 

can you share a sample file to analyze? save it as pdf with Illustrator compatibility and attach it here. Or upload your ai file to Google Drive, Creative Cloud or similar and post the link here

Participating Frequently
March 30, 2023

Okay, I got the script where it runs, but I don't get any layer name benefits.

 

Step 1 - I have a layer with lots of little elements in it.

Step 2 - I release those to layers (sequence), so now I have a layer full of other layers.

Step 3 - run script and still have to rename all these layers.

Previously, I would simply pull the Step 2 layers out of Layer 1 and then rename. I would rather prefer to go from Step 1 (layer with named elements) to Step 4 (all elements are on their own relevantly named layers) without having to individually name the layers. I was hoping this script would do that, but it seems to just rename the released Layer # (etc) to <layer #> with my relevant element names still trapped inside and useless when I bring it into AE.

Screen shots included of the 3 stages of "this isn't working for me and I don't know why."

 

Thanks!

CarlosCanto
Adobe Expert
January 22, 2021

wow 10 years later...

 

what SV said, plus download it again, I just fixed the index issue.

New Participant
June 25, 2021

10 years and 6 months later! Thank you so much for saving me from renaming 56 layers one at a time!

CarlosCanto
Adobe Expert
July 14, 2011

I'm confused, can you post a screen shot showing your layer structure (with default "layer #" names) and how you want it renamed?

byronnashAuthor
Participating Frequently
July 15, 2011

See the image below.

New Participant
April 21, 2016

here you go, select "Layer 1" and apply Release to Layers (sequence) before running

 

 

var idoc = app.activeDocument;

var ilayer = idoc.activeLayer;

for (i=0; i<ilayer.layers.length; i++)

     {

          var sublayer = ilayer.layers[i];

          sublayer.name = sublayer.pageItems[0].name;

     }

 


Hi Carlos - I'm not a scripting person and no nothing of syntax. How do I put this script into action on a Mac (Yosemite) using Illustrator CC 2015? What app do I use to write the script? Thanks for the help!