Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Rename layer comps

Community Beginner ,
Jul 31, 2022 Jul 31, 2022

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

}

}

}

TOPICS
Actions and scripting , Windows
3.2K
Translate
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

correct answers 3 Correct answers

Community Expert , Aug 02, 2022 Aug 02, 2022

@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];
        
...
Translate
Community Expert , Oct 06, 2023 Oct 06, 2023

@Johnathan3255409376r4 

 

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
...
Translate
Community Expert , Oct 06, 2023 Oct 06, 2023

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
...
Translate
Adobe
Community Beginner ,
Oct 06, 2023 Oct 06, 2023

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

Translate
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
Community Expert ,
Oct 06, 2023 Oct 06, 2023

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.

Translate
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
Community Beginner ,
Oct 06, 2023 Oct 06, 2023

I can do that later this evening, but no, no layer groups. Would it be better if I added groups?

Translate
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
Community Expert ,
Oct 06, 2023 Oct 06, 2023
quote

Would it be better if I added groups?


By @Johnathan3255409376r4

 

Arguably NO!

Translate
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
Community Expert ,
Oct 06, 2023 Oct 06, 2023

@Johnathan3255409376r4 

 

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

 

Translate
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
Community Beginner ,
Oct 06, 2023 Oct 06, 2023

Worked perfectly. Thank you so much!

Translate
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
Community Expert ,
Oct 06, 2023 Oct 06, 2023
LATEST

You're welcome!

Translate
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
Community Expert ,
Oct 06, 2023 Oct 06, 2023

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

 

Translate
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