Make Color Sampler in LAB mode

Participant ,
May 25, 2021 May 25, 2021

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 )}
TOPICS
Actions and scripting

Views

1.9K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , May 26, 2021 May 26, 2021
No, it won't work like that. Moreover, you did not write it correctly. Almost all lists are read-only properties. Such as for example histogram, compsList, printerList, targetLayers, etc. They cannot be changed with the "set" command.   Logically it should be like this 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...

Likes

Translate

Translate
Adobe Community Professional ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

with((cS = activeDocument.colorSamplers)[cS.length - 1].color.lab) [l, a, b]

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

thats useful

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 25, 2021 May 25, 2021

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

The info palette shows results depending on selected Color Mode.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

This property is stored in the ColoSampler itself. It can be read, but there is no way to change it at least in 2020.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Or else it stores binary SolidColor, then checks color mode and displayes result in such mode.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

It was necessary to create in this mode. It was a question.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Not possible, to do it you have to change color mode first, or get lab colour result by script.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

This will be Actual Color, not pure LAB Color. It will change depending on the document mode.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 25, 2021 May 25, 2021

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)

colorsample.png

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Then 1x1 px selctions instead of ColorSamplers can be solution?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Probably meant 31x31?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

Yes, that's right, by maybe Gibson Editions won't need this extensive scope 🙂

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 25, 2021 May 25, 2021

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... 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

for the panel options that is. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 26, 2021 May 26, 2021

Copy link to clipboard

Copied

What you mean by changing color sampler manually?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 26, 2021 May 26, 2021

Copy link to clipboard

Copied

Screenshot 2021-05-26 at 13.37.19.png

 

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"))

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 26, 2021 May 26, 2021

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}}}]}

 

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 26, 2021 May 26, 2021

Copy link to clipboard

Copied

No, it won't work like that. Moreover, you did not write it correctly.
Almost all lists are read-only properties.
Such as for example histogram, compsList, printerList, targetLayers, etc.
They cannot be changed with the "set" command.
 
Logically it should be like this
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);
 
but doesn't work.
Although if you change "colorSampler" to "compsClass" everything works fine. This is a flaw in Photoshop. There are a lot of them.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 26, 2021 May 26, 2021

Copy link to clipboard

Copied

LATEST

Thank you so much for you expertise, thats really helpful.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines