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!
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.
Copy link to clipboard
Copied
The id attribute doesn't seem to be available to layer items, only comps and folders?
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.
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();
}
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!
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();
}
Copy link to clipboard
Copied
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 👍