Copy link to clipboard
Copied
I am trying to create a new color sampler using a LAB readout, but cant get this homecooked function of mine to work. not sure if i have the putEnumerated for lab in right context in the descriptor. Any ideas....
newColorSampler (100, 200)
function newColorSampler(xpos, ypos){
function s2t(s) {return stringIDToTypeID(s)}
var d1 = new ActionDescriptor()
var r1 = new ActionReference()
r1.putClass( s2t( "colorSampler" ))
d1.putReference( s2t( "null" ), r1 )
d1.putEnumerated(s2t("colorSpace"),s2t("colorSpace"), s2t("labColor"))
var d2 = new ActionDescriptor()
d2.putUnitDouble( s2t( "horizontal" ), s2t( "pixelsUnit" ), xpos )
d2.putUnitDouble( s2t( "vertical" ), s2t( "pixelsUnit" ), ypos )
d1.putObject(s2t( "position" ), s2t( "paint" ), d2 )
executeAction(s2t( "make" ), d1, DialogModes.NO )}
var class_name = "colorSampler";
var d = new ActionDescriptor();
var r = new ActionReference()
r.putIndex(stringIDToTypeID(class_name), 1);
d.putReference(stringIDToTypeID("null"), r);
var d1 = new ActionDescriptor();
//d
Copy link to clipboard
Copied
with((cS = activeDocument.colorSamplers)[cS.length - 1].color.lab) [l, a, b]
Copy link to clipboard
Copied
thats useful
Copy link to clipboard
Copied
The logic is correct. But it won't work. Probably the developers of photoshop did not foresee such an opportunity or simply did not notice.
Copy link to clipboard
Copied
The info palette shows results depending on selected Color Mode.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Or else it stores binary SolidColor, then checks color mode and displayes result in such mode.
Copy link to clipboard
Copied
It was necessary to create in this mode. It was a question.
Copy link to clipboard
Copied
Not possible, to do it you have to change color mode first, or get lab colour result by script.
Copy link to clipboard
Copied
This will be Actual Color, not pure LAB Color. It will change depending on the document mode.
Copy link to clipboard
Copied
ColorSampler is a bad tool in scripts.
Here is a real ColorSampler 31x31.
See what the code shows
alert (activeDocument.colorSamplers [0] .color.rgb.red)
Copy link to clipboard
Copied
Then 1x1 px selctions instead of ColorSamplers can be solution?
Copy link to clipboard
Copied
Probably meant 31x31?
Copy link to clipboard
Copied
Yes, that's right, by maybe Gibson Editions won't need this extensive scope 🙂
Copy link to clipboard
Copied
I am reading the numbers in LAB but my document is in RGB.
its strange, as i can read the enumeration in LAB if ive changed the color sampler manually.
I dont know whether it is described inside toolPreferences perhaps...
Copy link to clipboard
Copied
for the panel options that is.
Copy link to clipboard
Copied
What you mean by changing color sampler manually?
Copy link to clipboard
Copied
This is the stucture i have found
function s2t(s) {return stringIDToTypeID(s)}
function t2s(t){return typeIDToStringID(t)}
function c2t(s) {return charIDToTypeID(s)}
var r1=new ActionReference();
var d1=new ActionDescriptor();
r1.putEnumerated(s2t("document"),s2t("ordinal"),s2t("targetEnum"));
d1=executeActionGet(r1);
l1 = d1.getList (s2t ("colorSamplerList"))
l1.count
d2 = l1.getObjectValue(0) //colorSampler 3 items // position (obj), color(obj), colorspace(enum)
o1 = d2.getObjectValue(s2t ("position")) // 2 items
o2 = d2.getObjectValue(s2t ("color")) //3 items
o3 = d2.getEnumerationValue(stringIDToTypeID("colorSpace"))
L = o2.getDouble(stringIDToTypeID("luminance"))
A = o2.getDouble(stringIDToTypeID("a"))
B = o2.getDouble(stringIDToTypeID("b"))
 
Copy link to clipboard
Copied
This is where im up to, any ideas how to make it work?...
I've never used lists before so not sure if im describing the list correctly...
Also not sure if "to" is correct for putObject
function s2t(s) {return stringIDToTypeID(s)}
var r1 = new ActionReference();
var d1 = new ActionDescriptor();
var d2 = new ActionDescriptor();
var l1 = new ActionList()
//l1.putList(s2t("colorSamplerList"), 0)
r1.putProperty(s2t("property"),s2t("colorSamplerList"));
r1.putEnumerated(s2t("document"),s2t ("ordinal"), s2t ("targetEnum"));
d1.putReference( s2t( "target" ), r1 )
l1.putInteger( 0 )
d2.putList(s2t("colorSampler"), l1);
d2.putEnumerated(s2t("colorSpace"),s2t("colorSpace"), s2t("labColor"))
d1.putObject(s2t("to"), s2t("colorSampler"),d2);
executeAction( s2t("set"), d1, DialogModes.NO );
//FAILS
This is an example of Structure in JSON
{"_obj":"object","colorSamplerList":[
{"_obj":"colorSampler",
"color":{"_obj":"labColor","a":0.0,"b":0.01,"luminance":99.73},
"colorSpace":{"_enum":"colorSpace","_value":"labColor"},
"position":{"_obj":"paint","horizontal":{"_unit":"pixelsUnit","_value":100.0},"vertical":{"_unit":"pixelsUnit","_value":200.0}}},
{"_obj":"colorSampler",
"color{"_obj":"RGBColor","blue":254.99221789883269,"grain":255.0,"red":255.0},
"colorSpace":{"_enum":"colorSpace","_value":"RGBColor"},
"position":{"_obj":"paint","horizontal":{"_unit":"pixelsUnit","_value":138.5},"vertical":{"_unit":"pixelsUnit","_value":111.5}}}]}
Copy link to clipboard
Copied
var class_name = "colorSampler";
var d = new ActionDescriptor();
var r = new ActionReference()
r.putIndex(stringIDToTypeID(class_name), 1);
d.putReference(stringIDToTypeID("null"), r);
var d1 = new ActionDescriptor();
//d1.put... some properties
d.putObject(stringIDToTypeID("to"), stringIDToTypeID(class_name), d1);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
Copy link to clipboard
Copied
Thank you so much for you expertise, thats really helpful.