Skip to main content
Inspiring
July 25, 2013
Answered

How to get the fill color of shape or solid color fill layers?

  • July 25, 2013
  • 1 reply
  • 1771 views

Hi All,

I am trying to get the fill color values of shape or solid color fill layers.

I get the kind of active layer i.e. SOLIDFILL, but there is no color like property to get the color for shape or solid color fill layers.

Is there any way or script to do that?

Please help me on this.

Thanks,
AI

This topic has been closed for replies.
Correct answer c.pfaffenbichler

I have not bothered with checking the type of the active layer, but if one Solid Color Layer is selected this should help.

// based on code by michael l hale;

var ref = new ActionReference();

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

var layerDesc = executeActionGet(ref);

var adjList = layerDesc.getList(stringIDToTypeID('adjustment'));

var theColors = adjList.getObjectValue(0).getObjectValue(stringIDToTypeID('color'));

var str = '';

for(var i=0;i<theColors.count;i++){ //enumerate descriptor's keys

       str = str + 'Key '+i+' = '+typeIDToStringID(theColors.getKey(i))+': '+theColors.getUnitDoubleValue(theColors.getKey(i))+'\n';

}

alert(str);

1 reply

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
July 25, 2013

I have not bothered with checking the type of the active layer, but if one Solid Color Layer is selected this should help.

// based on code by michael l hale;

var ref = new ActionReference();

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

var layerDesc = executeActionGet(ref);

var adjList = layerDesc.getList(stringIDToTypeID('adjustment'));

var theColors = adjList.getObjectValue(0).getObjectValue(stringIDToTypeID('color'));

var str = '';

for(var i=0;i<theColors.count;i++){ //enumerate descriptor's keys

       str = str + 'Key '+i+' = '+typeIDToStringID(theColors.getKey(i))+': '+theColors.getUnitDoubleValue(theColors.getKey(i))+'\n';

}

alert(str);

Inspiring
July 25, 2013

Thanks a lot, this is exactly what i need..

c.pfaffenbichler
Community Expert
Community Expert
July 25, 2013

You’re welcome.