Skip to main content
999tevashkevich
Known Participant
August 6, 2016
Answered

Detect if Group has a "color" set on it (see pic inside)

  • August 6, 2016
  • 1 reply
  • 232 views

Hey everyone

Working on another feature for one of my extensions and I'm trying to see if it's viable to just have the user set group colors for me to look over and grab/export off of.

The colors I'm talking about is the ones like below (accessed by right click and putting a color on it. Also works on layers as well)

I already grabbed listener code to "Set" or "Clear" them but that doesn't help me in figuring out how I can actually find if a group has one set in script or not

Has anyone done this by chance?

This topic has been closed for replies.
Correct answer SuperMerlin

Works on active layer/group.

alert(getLayerColour());

function getLayerColour(){

//Colours returned ....

// "none","red","orange","yellowColor","grain","blue","violet","gray"

var ref = new ActionReference();

   ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

   var appDesc = executeActionGet(ref);

  return typeIDToStringID(appDesc.getEnumerationValue(stringIDToTypeID('color')) );

};

1 reply

SuperMerlin
SuperMerlinCorrect answer
Inspiring
August 6, 2016

Works on active layer/group.

alert(getLayerColour());

function getLayerColour(){

//Colours returned ....

// "none","red","orange","yellowColor","grain","blue","violet","gray"

var ref = new ActionReference();

   ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

   var appDesc = executeActionGet(ref);

  return typeIDToStringID(appDesc.getEnumerationValue(stringIDToTypeID('color')) );

};

999tevashkevich
Known Participant
August 6, 2016

Sweet deal. I never thought to use store the execute like that.

TIL.

This might even help make it a bit easier/quicker as well but I'll have to do some testing.

Thinking maybe have the user set the colors on the groups they want to export into what ever channel and select and run the script (so I have the groups already and don't have to iterate and can just check colors) Should be able to iterate a returned array from the appDesc I'm guessing right?

SuperMerlin
Inspiring
August 6, 2016

You should be able to get the same information using the Layer Index or the Layer ID

ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); //activeLayer

ref.putIndex( charIDToTypeID( 'Lyr ' ), idx); //Layer Index

ref.putIdentifier(charIDToTypeID('Lyr '), ID); //Layer Id