Copy link to clipboard
Copied
This is the layer renaming script I am using now. I want to change it to only rename the layer comps. How can I modify the code?
Tthank you very much~
app.bringToFront();
if (documents.length == 0) {
alert("No documents to process");
}
else{
var visibility = false;
var docRef = activeDocument;
changeLayerName(docRef);
}
function changeLayerName(layer){
var layers = layer.layers;
if(layers){
for(var i = 0; i < layers.length; i ++){
layers[i].name = "Layer " + [i];
changeLayerName(layers[i]);
}
}
}
@jimmy0918 – Your original code for top-level layers, modified for only top-level Layer Groups/Sets (not for sets within sets within sets etc):
app.bringToFront();
if (documents.length == 0) {
alert("No documents to process");
} else {
var docRef = activeDocument;
changeLayerName(docRef);
}
function changeLayerName(layer) {
var layers = layer.layerSets;
if (layers) {
for (var i = 0; i < layers.length; i++) {
layers[i].name = "Layer Set " + [i];
...
Try the following code to rename existing comps using layer visibility:
/*
https://community.adobe.com/t5/photoshop-ecosystem-discussions/rename-layer-comps/m-p/14139107
Rename Layer Comps to Visible Layer Names.jsx
v1.0 7th October 2023, Stephen Marsh
Based on:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/rename-layer-comps/td-p/13104526
https://community.adobe.com/t5/photoshop-ecosystem-discussions/export-jpg-and-combining-the-visual-layer-names-to
...
As my previous script was reactive, renaming existing comps, the following script might be preferred as it is proactive.
Create a new comp using the visible layer names:
/*
https://community.adobe.com/t5/photoshop-ecosystem-discussions/rename-layer-comps/m-p/14139107
Add Layer Comp Using Visible Layer Names.jsx
v1.0 7th October 2023, Stephen Marsh
*/
#target photoshop
// Set the layer variable
var theLayers = activeDocument.layers;
// Create an empty array to hold the layer names
var laye
...
Copy link to clipboard
Copied
I want the layer comps to be renamed to the visible layers. So for example - referencing the above screenshot, i would like the layer comp to be renamed "Welcome_LightBlue_Waves". Right now, it is named Layer Comp 12.
Layer Comp 12 = Welcome, LightBlue, Waves are the only layers visible
Would like the Layer Comp changed name to be: Welcome_LightBlue_Waves
Layer Comp 13 = Welcome, LightBlue, Stone are the only visible layers
Would like the Layer Comp changed name to be: Welcome_LightBlue_Stone
Layer Comp 14 = Welcome, LightBlue, Grunge are the only visible layers
Would like the Layer Comp changed name to be: Welcome_LightBlue_Grunge
etc etc
Not sure how I can show that in screenshots
Copy link to clipboard
Copied
Post a cropped screenshot of the layers panel with the layers visible for a particular layer comp. It is important to know if there are layer groups etc.
You could also upload a copy of the PSD with comps, it could be resized to a very small pixel dimension.
Copy link to clipboard
Copied
I can do that later this evening, but no, no layer groups. Would it be better if I added groups?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Try the following code to rename existing comps using layer visibility:
/*
https://community.adobe.com/t5/photoshop-ecosystem-discussions/rename-layer-comps/m-p/14139107
Rename Layer Comps to Visible Layer Names.jsx
v1.0 7th October 2023, Stephen Marsh
Based on:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/rename-layer-comps/td-p/13104526
https://community.adobe.com/t5/photoshop-ecosystem-discussions/export-jpg-and-combining-the-visual-layer-names-to-create-the-file-name/m-p/13617072
*/
#target photoshop
function renameComps() {
// Set the layer variable
var theLayers = activeDocument.layers;
// Backwards loop over the comps
//for (var i = activeDocument.layerComps.length - 1; i >= 0; i--) {
// Forwards loop over the comps
for (var i = 0; i < activeDocument.layerComps.length; i++) {
// Select each comp
activeDocument.layerComps[i].apply();
// Create an empty array to hold the layer names
var layerNames = [];
// Backwards loop over the top-level layers
//for (var j = theLayers.length - 1; j >= 0; j--) {
// Forwards loop over the top-level layers
for (var j = 0; j < theLayers.length; j++) {
if (theLayers[j].visible === true) {
// Push the layer names to the array
layerNames.push(theLayers[j].name);
}
}
// Join the layer names with an underscore separator
var joinLayerNames = layerNames.join("_");
// Rename the layer comp
activeDocument.layerComps[i].name = joinLayerNames;
}
}
activeDocument.suspendHistory("Rename Layer Comps to Visible Layer Names.jsx", "renameComps()");
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html
Copy link to clipboard
Copied
Worked perfectly. Thank you so much!
Copy link to clipboard
Copied
You're welcome!
Copy link to clipboard
Copied
As my previous script was reactive, renaming existing comps, the following script might be preferred as it is proactive.
Create a new comp using the visible layer names:
/*
https://community.adobe.com/t5/photoshop-ecosystem-discussions/rename-layer-comps/m-p/14139107
Add Layer Comp Using Visible Layer Names.jsx
v1.0 7th October 2023, Stephen Marsh
*/
#target photoshop
// Set the layer variable
var theLayers = activeDocument.layers;
// Create an empty array to hold the layer names
var layerNames = [];
// Backwards loop over the top-level layers
//for (var j = theLayers.length - 1; j >= 0; j--) {
// Forwards loop over the top-level layers
for (var j = 0; j < theLayers.length; j++) {
if (theLayers[j].visible === true) {
// Push the layer names to the array
layerNames.push(theLayers[j].name);
}
}
// Join the layer names with an underscore separator
var joinLayerNames = layerNames.join("_");
// Add the layer comp (String name, String comment, bool appearance, bool position, bool visibility)
activeDocument.layerComps.add(joinLayerNames, '', true, true, true);