Skip to main content
Participant
March 14, 2014
Answered

Get stroke color of shape

  • March 14, 2014
  • 1 reply
  • 1272 views

Hi,

I need get stroke color of shape in photoshop, but I only find how to get fill color, any suggestion?

function getFillColor() {

   var ref = new ActionReference();

   ref.putEnumerated( stringIDToTypeID( "contentLayer" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ));

   var ref1= executeActionGet( ref );

   var list =  ref1.getList( charIDToTypeID( "Adjs" ) ) ;

   var solidColorLayer = list.getObjectValue(0);      

   var color = solidColorLayer.getObjectValue(charIDToTypeID('Clr '));

   var fillcolor = new SolidColor();

   fillcolor.rgb.red = color.getDouble(charIDToTypeID('Rd  '));

   fillcolor.rgb.green = color.getDouble(charIDToTypeID('Grn '));

   fillcolor.rgb.blue = color.getDouble(charIDToTypeID('Bl  '));

   return fillcolor;

}

Thank you

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

Does this work in Photoshop CC? (edited)

// 2014, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var ref = new ActionReference();

ref.putEnumerated( stringIDToTypeID("contentLayer"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var layerDesc = executeActionGet(ref);

var strokeSt = layerDesc.getObjectValue(stringIDToTypeID("AGMStrokeStyleInfo"));

var strokeStyleColor = strokeSt.getObjectValue(stringIDToTypeID("strokeStyleContent")).getObjectValue(stringIDToTypeID("color"));

alert (strokeStyleColor.getDouble(stringIDToTypeID("red"))+"\n"+strokeStyleColor.getDouble(stringIDToTypeID("grain"))+"\n"+strokeStyleColor.getDouble(stringIDToTypeID("blue")));

};

1 reply

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
March 15, 2014

Does this work in Photoshop CC? (edited)

// 2014, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var ref = new ActionReference();

ref.putEnumerated( stringIDToTypeID("contentLayer"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var layerDesc = executeActionGet(ref);

var strokeSt = layerDesc.getObjectValue(stringIDToTypeID("AGMStrokeStyleInfo"));

var strokeStyleColor = strokeSt.getObjectValue(stringIDToTypeID("strokeStyleContent")).getObjectValue(stringIDToTypeID("color"));

alert (strokeStyleColor.getDouble(stringIDToTypeID("red"))+"\n"+strokeStyleColor.getDouble(stringIDToTypeID("grain"))+"\n"+strokeStyleColor.getDouble(stringIDToTypeID("blue")));

};

Participant
July 10, 2015

Sorry for reviving this old post but...

I've been trying to get a shape's stroke color for a whole week now, with no success. Tried the ScriptingListener, didn't find anything useful (or it did for SETTING the color, not for GETTING it). The missing link was that "AGMStrokeStyleInfo" ID... how did you find it, if I may ask?

I THANK YOU DEEPLY, SIR!

Really you can't imagine just how much of a godsend this is for me right now! Haha!

Cheers,

Tudor.

PS: I've tried the code on CC 2015 and works.

c.pfaffenbichler
Community Expert
Community Expert
July 12, 2015

I pretty much use code based on code by Mike Hale (though it may include contributions from Paul or xbytor and/or others) to get the parameters of Application/Document/Layer etc. as needed.

// based on code by michael l hale;

// 2015, use it at your own risk;

//#target photoshop

#target "photoshop-70.032"

if (app.documents.length > 0) {

var ref = new ActionReference();

// the layer;

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

// the application;

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

// the document;

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

var layerDesc = executeActionGet(ref);

checkDesc2 (layerDesc);

};

//////

////// based on code by michael l hale //////

function checkDesc2 (theDesc) {

var c = theDesc.count;

var str = '';

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

  str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+'\n'+getValues (theDesc, i)+'\n';

  };

alert("desc\n\n"+str);

};

////// check //////

function getValues (theDesc, theNumber) {

switch (theDesc.getType(theDesc.getKey(theNumber))) {

case DescValueType.BOOLEANTYPE:

return theDesc.getBoolean(theDesc.getKey(theNumber));

break;

case DescValueType.CLASSTYPE:

return theDesc.getClass(theDesc.getKey(theNumber));

break;

case DescValueType.DOUBLETYPE:

return theDesc.getDouble(theDesc.getKey(theNumber));

break;

case DescValueType.ENUMERATEDTYPE:

return (typeIDToStringID(theDesc.getEnumerationValue(theDesc.getKey(theNumber)))+"_"+typeIDToStringID(theDesc.getEnumerationType(theDesc.getKey(theNumber))));

break;

case DescValueType.INTEGERTYPE:

return theDesc.getInteger(theDesc.getKey(theNumber));

break;

case DescValueType.LISTTYPE:

return theDesc.getList(theDesc.getKey(theNumber));

break;

case DescValueType.OBJECTTYPE:

return (theDesc.getObjectValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getObjectType(theDesc.getKey(theNumber))));

break;

case DescValueType.REFERENCETYPE:

return theDesc.getReference(theDesc.getKey(theNumber));

break;

case DescValueType.STRINGTYPE:

return theDesc.getString(theDesc.getKey(theNumber));

break;

case DescValueType.UNITDOUBLE:

return (theDesc.getUnitDoubleValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getUnitDoubleType(theDesc.getKey(theNumber))));

break;

default:

break;

};

};

For a Shape Layer with a Stroke this would get me

Key 0 = name: DescValueType.STRINGTYPE

Color Fill 1

Key 1 = color: DescValueType.ENUMERATEDTYPE

none_color

Key 2 = visible: DescValueType.BOOLEANTYPE

true

Key 3 = mode: DescValueType.ENUMERATEDTYPE

normal_blendMode

Key 4 = opacity: DescValueType.INTEGERTYPE

255

Key 5 = layerID: DescValueType.INTEGERTYPE

2

Key 6 = itemIndex: DescValueType.INTEGERTYPE

2

Key 7 = count: DescValueType.INTEGERTYPE

2

Key 8 = preserveTransparency: DescValueType.BOOLEANTYPE

false

Key 9 = layerFXVisible: DescValueType.BOOLEANTYPE

false

Key 10 = globalAngle: DescValueType.INTEGERTYPE

120

Key 11 = background: DescValueType.BOOLEANTYPE

false

Key 12 = layerSection: DescValueType.ENUMERATEDTYPE

layerSectionContent_layerSectionType

Key 13 = layerLocking: DescValueType.OBJECTTYPE

[ActionDescriptor]_layerLocking

Key 14 = group: DescValueType.BOOLEANTYPE

false

Key 15 = targetChannels: DescValueType.LISTTYPE

[ActionList]

Key 16 = visibleChannels: DescValueType.LISTTYPE

[ActionList]

Key 17 = channelRestrictions: DescValueType.LISTTYPE

[ActionList]

Key 18 = fillOpacity: DescValueType.INTEGERTYPE

255

Key 19 = hasUserMask: DescValueType.BOOLEANTYPE

false

Key 20 = hasVectorMask: DescValueType.BOOLEANTYPE

true

Key 21 = layerKind: DescValueType.INTEGERTYPE

4

Key 22 = hasFilterMask: DescValueType.BOOLEANTYPE

false

Key 23 = userMaskDensity: DescValueType.INTEGERTYPE

255

Key 24 = userMaskFeather: DescValueType.DOUBLETYPE

0

Key 25 = vectorMaskDensity: DescValueType.INTEGERTYPE

255

Key 26 = vectorMaskFeather: DescValueType.DOUBLETYPE

0

Key 27 = adjustment: DescValueType.LISTTYPE

[ActionList]

Key 28 = bounds: DescValueType.OBJECTTYPE

[ActionDescriptor]_rectangle

Key 29 = boundsNoEffects: DescValueType.OBJECTTYPE

[ActionDescriptor]_rectangle

Key 30 = useAlignedRendering: DescValueType.BOOLEANTYPE

false

Key 31 = generatorSettings: DescValueType.OBJECTTYPE

[ActionDescriptor]_generatorSettings

Key 32 = AGMStrokeStyleInfo: DescValueType.OBJECTTYPE

[ActionDescriptor]_strokeStyle

Then

checkDesc2 (layerDesc.getObjectValue(stringIDToTypeID("AGMStrokeStyleInfo")));

can be used to check out the details for AGMStrokeStyleInfo.