Need to make sure layer names are unique

Explorer ,
Nov 21, 2012 Nov 21, 2012

Copy link to clipboard

Copied

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!

TOPICS
Scripting

Views

1.1K

Likes

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
Contributor ,
Nov 21, 2012 Nov 21, 2012

Copy link to clipboard

Copied

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

Likes

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
New Here ,
Mar 12, 2013 Mar 12, 2013

Copy link to clipboard

Copied

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

Likes

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 ,
Nov 28, 2012 Nov 28, 2012

Copy link to clipboard

Copied

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

Wrap it in a function.

Likes

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
Advocate ,
Mar 14, 2013 Mar 14, 2013

Copy link to clipboard

Copied

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

}

Likes

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 ,
Jun 22, 2022 Jun 22, 2022

Copy link to clipboard

Copied

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!

Likes

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
Adobe Community Professional ,
Jun 22, 2022 Jun 22, 2022

Copy link to clipboard

Copied

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

Likes

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 ,
Jun 24, 2022 Jun 24, 2022

Copy link to clipboard

Copied

LATEST

I apologise, I found this thread through searching on Google - I noticed after I replied that this is for After Effects, not Photoshop! I found an answer in the end asking on the photoshop forum 👍

Likes

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