Answered
Display the layer color of the active layer stroke
Hello everyone!
Is there any way to check the color code of the stroke applied to the layer with active effects with scripts? Thanks.

Hello everyone!
Is there any way to check the color code of the stroke applied to the layer with active effects with scripts? Thanks.

Here is an example for active layer....
var S ={}
S = getStrokeFX();
for(var a in S){
$.writeln(a + " = " + S[a]);
}
function getStrokeFX(){
var Stroke ={};
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if(desc.hasKey(stringIDToTypeID( 'layerEffects' ))){
if(!desc.getBoolean (stringIDToTypeID( 'layerFXVisible'))) return undefined;
desc = desc.getObjectValue(stringIDToTypeID('layerEffects'));
if(!desc.hasKey(stringIDToTypeID( 'frameFX'))) return null;
desc = desc.getObjectValue(stringIDToTypeID('frameFX'));
Stroke.Enabled = desc.getBoolean(stringIDToTypeID('enabled'));
Stroke.Mode = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'mode' )));
Stroke.Style = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'style' )));
Stroke.PaintType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'paintType' )));
Stroke.Opacity = desc.getUnitDoubleValue (stringIDToTypeID( 'opacity' ));
Stroke.Size = desc.getUnitDoubleValue (stringIDToTypeID( 'size' ));
if(desc.hasKey (stringIDToTypeID('color'))){
var cColour = getColorFromDescriptor(desc.getObjectValue(stringIDToTypeID("color")), typeIDToCharID(desc.getClass(stringIDToTypeID("color"))));
Stroke.Colour = cColour.rgb.hexValue;
}
if(desc.hasKey (stringIDToTypeID('gradient'))){
Stroke.Angle = desc.getUnitDoubleValue (stringIDToTypeID( 'angle' ));
Stroke.Type = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'type' )));
Stroke.Reverse = desc.getBoolean(stringIDToTypeID('reverse'));
Stroke.Dither = desc.getBoolean(stringIDToTypeID('dither'));
Stroke.Scale = desc.getUnitDoubleValue (stringIDToTypeID( 'scale' ));
Stroke.Align = desc.getBoolean(stringIDToTypeID('align'));
var gradientDesc = desc.getObjectValue(stringIDToTypeID('gradient'));
Stroke.Name = gradientDesc.getString(stringIDToTypeID('name'));
Stroke.GradientForm = typeIDToStringID(gradientDesc.getEnumerationValue( stringIDToTypeID( 'gradientForm' )));
Stroke.InterfaceIconFrameDimmed = gradientDesc.getUnitDoubleValue (stringIDToTypeID( 'interfaceIconFrameDimmed' ));
var colorDesc = gradientDesc.getList(stringIDToTypeID( 'colors'));
var cCount = colorDesc.count;
Stroke.GradientColours = [];
Stroke.GradientType = [];
Stroke.GradientLocation = [];
Stroke.GradientMidpoint = [];
for(var a = 0;a<cCount;a++){
var gradDesc = desc.getObjectValue(stringIDToTypeID('gradient')).getList(stringIDToTypeID('colors')).getObjectValue(a);
var gColour = getColorFromDescriptor(gradDesc.getObjectValue(stringIDToTypeID("color")), typeIDToCharID(gradDesc.getClass(stringIDToTypeID("color"))));
Stroke.GradientColours.push(gColour.rgb.hexValue);
Stroke.GradientType.push(typeIDToStringID(gradDesc.getEnumerationValue( stringIDToTypeID( 'type' ))));
Stroke.GradientLocation.push(gradDesc.getInteger (stringIDToTypeID( 'location' )));
Stroke.GradientMidpoint.push(gradDesc.getInteger (stringIDToTypeID( 'midpoint' )));
}
var tranDesc = gradientDesc.getList(stringIDToTypeID( 'transparency'));
var tCount = tranDesc.count;
Stroke.TransparencyOpacity = [];
Stroke.TransparencyLocation = [];
Stroke.TransparencyMidpoint = [];
for(var a = 0;a<tCount;a++){
var tDesc = desc.getObjectValue(stringIDToTypeID('gradient')).getList(stringIDToTypeID('transparency')).getObjectValue(a);
Stroke.TransparencyOpacity.push(tDesc.getUnitDoubleValue (stringIDToTypeID( 'opacity' )));
Stroke.TransparencyLocation.push(tDesc.getInteger (stringIDToTypeID( 'location' )));
Stroke.TransparencyMidpoint.push(tDesc.getInteger (stringIDToTypeID( 'midpoint' )));
}
var offsetDesc = desc.getObjectValue(stringIDToTypeID('offset'));
Stroke.OffsetHorizontal = offsetDesc.getUnitDoubleValue (stringIDToTypeID( 'horizontal' ));
Stroke.OffsetVertical = offsetDesc.getUnitDoubleValue (stringIDToTypeID( 'vertical' ));
}
if(desc.hasKey (stringIDToTypeID('pattern'))){
var patternDesc = desc.getObjectValue(stringIDToTypeID('pattern'));
Stroke.Scale = desc.getUnitDoubleValue (stringIDToTypeID( 'scale' ));
Stroke.Linked = desc.getBoolean(stringIDToTypeID('linked'));
Stroke.PatternName = patternDesc.getString(stringIDToTypeID('name'));
Stroke.PatternID = patternDesc.getString(stringIDToTypeID('ID'));
var phaseDesc = desc.getObjectValue(stringIDToTypeID('phase'));
Stroke.PatternHorizontal = phaseDesc.getUnitDoubleValue (stringIDToTypeID( 'horizontal' ));
Stroke.PatternVertical = phaseDesc.getUnitDoubleValue (stringIDToTypeID( 'vertical' ));
}
}
return Stroke;
};
function getColorFromDescriptor(colorDesc, keyClass) {
var colorObject = new SolidColor();
switch (keyClass) {
case "Grsc":
colorObject.grey.grey = color.getDouble(charIDToTypeID('Gry '));
break;
case "RGBC":
colorObject.rgb.red = colorDesc.getDouble(charIDToTypeID('Rd '));
colorObject.rgb.green = colorDesc.getDouble(charIDToTypeID('Grn '));
colorObject.rgb.blue = colorDesc.getDouble(charIDToTypeID('Bl '));
break;
case "CMYC":
colorObject.cmyk.cyan = colorDesc.getDouble(charIDToTypeID('Cyn '));
colorObject.cmyk.magenta = colorDesc.getDouble(charIDToTypeID('Mgnt'));
colorObject.cmyk.yellow = colorDesc.getDouble(charIDToTypeID('Ylw '));
colorObject.cmyk.black = colorDesc.getDouble(charIDToTypeID('Blck'));
break;
case "LbCl":
colorObject.lab.l = colorDesc.getDouble(charIDToTypeID('Lmnc'));
colorObject.lab.a = colorDesc.getDouble(charIDToTypeID('A '));
colorObject.lab.b = colorDesc.getDouble(charIDToTypeID('B '));
break;
default:
return null;
}
return colorObject;
};
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.