Copy link to clipboard
Copied
Hi all,
I want to get the properties of gradient layer i.e. its name, color value and mode?
Also the properties like angle, style and scale that appears in Gradient Fill panel, when we create the Gradient layer?
Thanks
There are a lot of settings for a gradientFill adjustment layer. I think there are always at least two color stops( even if they are the same color ). And I am not sure what you mean by 'mode'.
Here is one way to get the settings from the layer.
...function getGradientFillAdjustmentInfo(){
if(app.documents.length==0 || app.activeDocument.activeLayer.kind != LayerKind.GRADIENTFILL ) return;
var gradientInfo = {};
gradientInfo.toString = function(){return "GradientInfo";}
var ref = new Acti
Copy link to clipboard
Copied
There are a lot of settings for a gradientFill adjustment layer. I think there are always at least two color stops( even if they are the same color ). And I am not sure what you mean by 'mode'.
Here is one way to get the settings from the layer.
function getGradientFillAdjustmentInfo(){
if(app.documents.length==0 || app.activeDocument.activeLayer.kind != LayerKind.GRADIENTFILL ) return;
var gradientInfo = {};
gradientInfo.toString = function(){return "GradientInfo";}
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref).getList(charIDToTypeID("Adjs")).getObjectValue(0);
if(desc.hasKey(charIDToTypeID("Dthr"))) gradientInfo.dither = desc.getBoolean(charIDToTypeID("Dthr"));
if(desc.hasKey(charIDToTypeID("Rvrs"))) gradientInfo.reverse = desc.getBoolean(charIDToTypeID("Rvrs"));
if(desc.hasKey(charIDToTypeID("Angl"))) gradientInfo.angle = desc.getDouble(charIDToTypeID("Angl"));
if(desc.hasKey(charIDToTypeID("Type"))) gradientInfo.type = typeIDToStringID(desc.getEnumerationValue(charIDToTypeID("Type")));
if(desc.hasKey(charIDToTypeID("Scl "))) gradientInfo.scale = desc.getDouble(charIDToTypeID("Scl "));
if(desc.hasKey(charIDToTypeID("Ofst"))){
gradientInfo.offset = [desc.getObjectValue(charIDToTypeID("Ofst")).getUnitDoubleValue(charIDToTypeID("Hrzn")),
desc.getObjectValue(charIDToTypeID("Ofst")).getUnitDoubleValue(charIDToTypeID("Vrtc"))];
}
desc = desc.getObjectValue(charIDToTypeID("Grad"));
gradientInfo.name = desc.getString(charIDToTypeID("Nm "));
gradientInfo.gradientForm = typeIDToStringID(desc.getEnumerationValue(charIDToTypeID("GrdF")));
var colorList = desc.getList(charIDToTypeID("Clrs"));
var transList = desc.getList(charIDToTypeID("Trns"));
gradientInfo.numberOfColorStops = colorList.count;
gradientInfo.colorStops = [];
for(var colorIndex=0;colorIndex<colorList.count;colorIndex++){
colorStopDesc = colorList.getObjectValue(colorIndex);
var colorStop = {};
colorStop.toString = function(){return "ColorStop";}
colorStop.location = colorStopDesc.getInteger(charIDToTypeID("Lctn"));
colorStop.midpoint = colorStopDesc.getInteger(charIDToTypeID("Mdpn"));
colorStop.type = typeIDToStringID(colorStopDesc.getEnumerationValue(charIDToTypeID("Type")));
colorStop.color = getColorFromDescriptor( colorStopDesc.getObjectValue(charIDToTypeID("Clr ")), typeIDToCharID(colorStopDesc.getClass(charIDToTypeID("Clr "))));
gradientInfo.colorStops.push(colorStop);
}
gradientInfo.numberOfTransStops = transList.count;
gradientInfo.transStops = [];
for(var transIndex=0;transIndex<transList.count;transIndex++){
transStopDesc = transList.getObjectValue(transIndex);
var transStop = {};
transStop.toString = function(){return "TransparencyStop";}
transStop.opacity = transStopDesc.getUnitDoubleValue(charIDToTypeID("Opct"));
transStop.location = transStopDesc.getInteger(charIDToTypeID("Lctn"));
transStop.midpoint = transStopDesc.getInteger(charIDToTypeID("Mdpn"));
gradientInfo.transStops.push(transStop);
}
return gradientInfo;
};
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 '));
case "HSBC":
colorObject.hsb.hue = colorDesc.getDouble(charIDToTypeID('H '));
colorObject.hsb.saturation = colorDesc.getDouble(charIDToTypeID('Strt'));
colorObject.hsb.brightness = colorDesc.getDouble(charIDToTypeID('Brgh'));
break;
default: return null;
}
return colorObject;
};
function alertProperties( obj ){
var str = obj +" properties:\r\r";
for (var p in obj) {
if(typeof obj
== "function") continue;
str += p + ': ' + obj
+"\r";
}
alert(str);
};
var someObjectName = getGradientFillAdjustmentInfo();
alertProperties( someObjectName );
alertProperties( someObjectName.colorStops[0] );
alertProperties( someObjectName.transStops[0] );
Copy link to clipboard
Copied
Thanks Michael, This is the same thing I am looking for.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now