Skip to main content
Gibson Editions
Inspiring
May 25, 2021
Answered

Make Color Sampler in LAB mode

  • May 25, 2021
  • 2 replies
  • 3780 views

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 )}
This topic has been closed for replies.
Correct answer r-bin

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

 

 

 


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.

2 replies

Brainiac
May 25, 2021

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.

Kukurykus
Brainiac
May 25, 2021

The info palette shows results depending on selected Color Mode.

Brainiac
May 25, 2021
This property is stored in the ColoSampler itself. It can be read, but there is no way to change it at least in 2020.
Kukurykus
Brainiac
May 25, 2021
with((cS = activeDocument.colorSamplers)[cS.length - 1].color.lab) [l, a, b]
Gibson Editions
Inspiring
May 26, 2021

thats useful