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 Expert ,
Jul 31, 2022 Jul 31, 2022

You need to address the LayerComps instead of the Layers then. 

Screenshot 2022-08-01 at 08.26.02.pngScreenshot 2022-08-01 at 08.26.11.png

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 ,
Aug 01, 2022 Aug 01, 2022

thanks
Because I don't know programming, according to your prompt, I can't succeed after modifying it many times.

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 ,
Aug 01, 2022 Aug 01, 2022

According to the documentation the name of a LayerComp is read-write, so what is the problem? 

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 ,
Aug 01, 2022 Aug 01, 2022

Please post the code you are working with at current. 

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 ,
Aug 01, 2022 Aug 01, 2022

app.bringToFront();

if (documents.length == 0) {

alert("没有可处理的文档");

}

else{

var visibility = false;

var docRef = activeDocument;

changeCompName(docRef);

}

function changeCompName(comp){

var comps = comp.LayerComp;

if(comps){

for(var i = 0; i < comps.length; i ++){
comps[i].name = "Comp" + [i];

changeCompName(comps[i]);

}

}

}

 

Use the above script without any prompts and changes
Where is the problem please?
thanks

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 ,
Aug 01, 2022 Aug 01, 2022
var comps = comp.LayerComp;

That’s not correctly written, please look at the screenshots I posted. 

var comps = comp.layerComps;

 

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 ,
Aug 01, 2022 Aug 01, 2022

app.bringToFront();

if (documents.length == 0) {

alert("没有可处理的文档");

}

else{

var visibility = false;

var docRef = activeDocument;

changeCompName(docRef);

}

function changeCompName(comp){

var comps = comp.LayerComps;

if(comps){

for(var i = 0; i < comps.length; i ++){
comps[i].name = "Comp" + [i];

changeCompName(comps[i]);

}

}

}

 

same no change

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 ,
Aug 01, 2022 Aug 01, 2022

Why did you capitalize the first letter? 

I did not write 

 

var comps = comp.LayerComps;

 

, I wrote:

 

var comps = comp.layerComps;

 

 

 

(edited)

Screenshot 2022-08-01 at 08.26.11.jpg

 

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 ,
Aug 01, 2022 Aug 01, 2022

Please forgive my harsh tone, JavaScript is case-sensitive and that may take some getting used to.

It makes a difference if one writes »LayerComps« or »layerComps«. 

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 ,
Aug 01, 2022 Aug 01, 2022

Thank you for your patient reply, but I changed it to lowercase and it still didn't work.

 

app.bringToFront();

if (documents.length == 0) {

alert("没有可处理的文档");

}

else{

var visibility = false;

var docRef = activeDocument;

changeCompName(docRef);

}

function changeCompName(comp){

var comps = comp.layerComps;

if(comps){

for(var i = 0; i < comps.length; i ++){
comps[i].name = "Comp" + [i];

changeCompName(comps[i]);

}

}

}

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 ,
Aug 01, 2022 Aug 01, 2022

Remove the line 

changeCompName(comps[i]);
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 ,
Aug 01, 2022 Aug 01, 2022

@jimmy0918 

 

Please try the following code:

 

// Rename Layer Comps.jsx

#target photoshop

function renameComps() {
    var counter = 1;
    for (i = 0; i < activeDocument.layerComps.length; i++) {
        myComps = activeDocument.layerComps[i];
        myComps.name = 'Comp ' + counter;
        counter++;
    }
}
app.activeDocument.suspendHistory("Rename Layer Comps.jsx", "renameComps()");
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 ,
Aug 01, 2022 Aug 01, 2022

Thanks for your reply
I use this code to test but nothing changes
I am using PS2022, will it have something to do with this?

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
Participant ,
Aug 01, 2022 Aug 01, 2022

Hi @jimmy0918,
Please try this code.

app.bringToFront();

if (documents.length == 0) {
alert("没有可处理的文档");
}

else{
var visibility = false;
var docRef = activeDocument;
changeCompName(docRef);
}

function changeCompName(comp){

var counter = 1;
for (i = 0; i < activeDocument.layerComps.length; i++) {
myComps = activeDocument.layerComps[i];
myComps.name = 'LayComp ' + counter;
counter++;
}
}


Thanks
Asuvath

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
Advocate ,
Aug 01, 2022 Aug 01, 2022

The last 3 scripts are working for me...

Are you sure that we are talking about layer comps and not layer sets?

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 ,
Aug 01, 2022 Aug 01, 2022

Good point. 

 

@jimmy0918, could you please post a screenshot with the pertinent Panels visible to clarify what you are trying to achieve. 

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 ,
Aug 02, 2022 Aug 02, 2022

1.JPG

I need to modify the names of these groups
thanks

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 ,
Aug 02, 2022 Aug 02, 2022

As @Tom Winkelmann surmised those are Groups, »layerSets« in DOM, not Layer Comps. 

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 ,
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];
            changeLayerName(layers[i]);
        }
    }
}

 

Or the code that I posted for Layer Comps, repurposed for Layer Groups/Sets:

 

#target photoshop

function renameSets() {
    var counter = 1;
    for (i = 0; i < activeDocument.layers.length; i++) {
        mySets = activeDocument.layerSets[i];
        mySets.name = 'Layer Group ' + counter;
        counter++;
    }
}
app.activeDocument.suspendHistory("Rename Layer Sets.jsx", "renameSets()");

 

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 ,
Aug 02, 2022 Aug 02, 2022

Please forgive my bad English, causing the previous description to be wrong.
Now these codes do what I want.
Thanks a lot for everyone's replies!

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 05, 2023 Oct 05, 2023

Is there anyway to update this script to Comp Layer names to be the visible layer for each comp?
The script I'm using just changes the names to whichever layer i have selected when I run the script:

app.bringToFront();

if (documents.length == 0) {

alert("No documents to process");

}

else{

var visibility = false;

var docRef = activeDocument;

changeCompName(docRef);

}

function changeCompName(comp){

var comps = comp.layerComps;

if(comps){

for(var i = 0; i < comps.length; i ++){
comps[i].name = docRef.activeLayer.name + [i];

changeCompName(comps[i]);

}

}

}

 

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 05, 2023 Oct 05, 2023

Could you please post screenshots with the pertinent Panels (Toolbar, Layers, Options Bar, …) visible to clarify what you mean? 

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 created a few hundred layer comps based on visibility combinations of layers only, using text layers, color layers, and background image layers.

 Snip90.JPG

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

Please post meaningful screenshots that actually illustrate the relation of the names of Layer Comps and visible Layers … 

 

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