Skip to main content
Participant
November 21, 2012
Question

Need to make sure layer names are unique

  • November 21, 2012
  • 3 replies
  • 1489 views

Is there any way to tell after effect to check if layer names are unique and if not update them? I know if you have two layers with the same names and try to pick whip to one, the layer names will update so they are unique, but is there any way to make this happen through scripting?

I'm exporting layer data and need to make sure all names are unique. I'm currently just working around this by adding the layer index to the end of the name, but I'd prefer a cleaner solution if available.

Thanks!

This topic has been closed for replies.

3 replies

Legend
March 15, 2013

This script will append the layer index number to the end of the layer name for all selected layers in the currently open comp.

var curComp = app.project.activeItem;

if(curComp instanceof CompItem){

          app.beginUndoGroup("Append index to name");

                    var myLayers = curComp.selectedLayers;

                    if(myLayers.length<1 || myLayers.length==null){

                              alert("Please select all the layers you want to process.");

                    }else{

                              for (var a=0; a<myLayers.length; a++) {

                                        var myLayer = myLayers;

                                        var selLayers = myLayer;

                                        var layerIndex = myLayers.index;

                                        var layerIndex = myLayer.index;

                                        myLayer.name = myLayer.name + " " + layerIndex.toString();

                              }

                              writeLn("All done");

                    }

          app.endUndoGroup();

}

bobd7221748
Inspiring
June 22, 2022

Your script is exactly what I've been looking for (renaming a layer to give it a unique name). However, when I try your script, I get the following error:

 

Error21: undefined is not an object.
Line: 1
-> var curComp = app.project.activeItem;

 

I understand this is an old post, so this is a long shot, however if you know how this can be fixed I would vastly appreciate it!

Dan Ebberts
Community Expert
Community Expert
June 22, 2022

Not sure why you're seeing that error, but make sure you have the layers you want to process selected, and try it this way:

var curComp = app.project.activeItem;
if(curComp != null && curComp instanceof CompItem){
	app.beginUndoGroup("Append index to name");
	var myLayers = curComp.selectedLayers;
	if(myLayers.length<1 || myLayers.length==null){
	      alert("Please select all the layers you want to process.");
	}else{
	      for (var a=0; a<myLayers.length; a++) {
			var myLayer = myLayers[a];
			myLayer.name = myLayer.name + " " + myLayer.index;
	      }
	}
	app.endUndoGroup();
}
Alan_AEDScripts
Inspiring
November 28, 2012

You could just put them in an array and loop through them and just amend the duplicates?

Wrap it in a function.

Inspiring
November 21, 2012

In fact, you does not need the name to be unique, just use the id attributes. It is also available for comps, folders, etc.

Participant
March 12, 2013

The id attribute doesn't seem to be available to layer items, only comps and folders?