Rename layer comps

Community Beginner ,
Jul 31, 2022 Jul 31, 2022

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

}

}

}

TOPICS
Actions and scripting , Windows

Views

162

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

correct answers 1 Correct answer

Adobe Community Professional , 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];
        
...

Likes

Translate

Translate
Adobe Community Professional ,
Jul 31, 2022 Jul 31, 2022

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

Please post the code you are working with at current. 

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

var comps = comp.LayerComp;

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

var comps = comp.layerComps;

 

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

 

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

Copy link to clipboard

Copied

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«. 

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

Copy link to clipboard

Copied

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

}

}

}

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

Copy link to clipboard

Copied

Remove the line 

changeCompName(comps[i]);

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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?

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

The last 3 scripts are working for me...

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

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

Copy link to clipboard

Copied

Good point. 

 

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

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

Copy link to clipboard

Copied

1.JPG

I need to modify the names of these groups
thanks

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

 

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

Copy link to clipboard

Copied

LATEST

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!

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