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

Photoshop Scripting - Assign color to layerSets

Explorer ,
Nov 23, 2023 Nov 23, 2023

Copy link to clipboard

Copied

Hi,

I've just started down the road of coding with Javascript and would love some help.

I've been searching all over and I can't seem to find a simple way to change the color of layerSets.

 

//Create OLD Folder
var grpOld = app.activeDocument.layerSets.add();
grpOld.name = "OLD";
grpOld.visible = 0;

 

In my code I'll like to add a line that just assigns the layerSet to the colors available i.e. no color, red, orange, yellow, green, blue, violet & gray.

 

keithm12552301_0-1700739463208.png

 

Any help on this would be great,

Thanks.

 

TOPICS
Actions and scripting , Windows

Views

333

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

Community Expert , Nov 23, 2023 Nov 23, 2023

 

// 2023, use it at your own risk;
colorLayer ("violet");
////// change color //////
function colorLayer(theColor){ 
try {
var desc33 = new ActionDescriptor();
var ref10 = new ActionReference();
var idLyr = charIDToTypeID("Lyr ");
ref10.putEnumerated(idLyr, charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
desc33.putReference(charIDToTypeID("null"), ref10 );
var desc34 = new ActionDescriptor();
var idClr = charIDToTypeID("Clr ");
desc34.putEnumerated(idClr, idClr, stringIDToTypeID(theColor));
de
...

Votes

Translate

Translate
Adobe
Community Expert ,
Nov 23, 2023 Nov 23, 2023

Copy link to clipboard

Copied

 

// 2023, use it at your own risk;
colorLayer ("violet");
////// change color //////
function colorLayer(theColor){ 
try {
var desc33 = new ActionDescriptor();
var ref10 = new ActionReference();
var idLyr = charIDToTypeID("Lyr ");
ref10.putEnumerated(idLyr, charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
desc33.putReference(charIDToTypeID("null"), ref10 );
var desc34 = new ActionDescriptor();
var idClr = charIDToTypeID("Clr ");
desc34.putEnumerated(idClr, idClr, stringIDToTypeID(theColor));
desc33.putObject(charIDToTypeID("T   "), idLyr, desc34);
executeAction(charIDToTypeID("setd"), desc33, DialogModes.NO);
}catch(e){
alert(e.message); 
}
};

 

Votes

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 ,
Nov 23, 2023 Nov 23, 2023

Copy link to clipboard

Copied

Appriciate it.

 

Is this taken from the javascript listener? It just seems so bloated.

 

Is there no simplier way? I know I'm being picky it just seems an excessive amount of code for what seems like such a simple task.

 

Thanks.

Votes

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 Expert ,
Nov 23, 2023 Nov 23, 2023

Copy link to clipboard

Copied

That’s Action Manager code, so essentially what you would get with ScriptingListener.plugin (although it is slightly »cleaned up«). 

 

Not all of Photoshop’s features are available via DOM code, so AM code it »has to be« sometimes. 

The advantage being that AM code usually runs faster. 

 

Votes

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 ,
Nov 23, 2023 Nov 23, 2023

Copy link to clipboard

Copied

Ah okay I see. That's unfortunate but thanks for your help. Used your code and it works as intended so happy days.

 

I'm going to keep learning some more code and hopefully wrap my head around all this Javascript coding to move onto UXP.

 

Thanks again.

Votes

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 Expert ,
Nov 23, 2023 Nov 23, 2023

Copy link to clipboard

Copied

Best of luck with UXP! 

I have tried familiarizing myself with that but so far I couldn’t muster the necessary focus and stamina. 

But in the long run it will probably be unavoidable. 

Votes

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 Expert ,
Nov 23, 2023 Nov 23, 2023

Copy link to clipboard

Copied

/*
No Color = "none"
Red = "red"
Orange = "orange"
Yellow = "yellowColor"
Green = "green"
Blue = "blue"
Violet = "violet"
Gray = "gray"
*/

Votes

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 ,
Nov 23, 2023 Nov 23, 2023

Copy link to clipboard

Copied

Hi Stephen,

 

Thanks for that. How would I implement that in the code I put in at the top?

 

Thanks.

Votes

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 Expert ,
Nov 23, 2023 Nov 23, 2023

Copy link to clipboard

Copied

The function provided by @c.pfaffenbichler has a parameter for "violet" in the function call. Just swap that for one of the other named colours. The reason that I posted the list is that yellowColor isn't obvious.

Votes

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 ,
Nov 23, 2023 Nov 23, 2023

Copy link to clipboard

Copied

LATEST

Ah sorry. I get you. Thank you.

Votes

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