Skip to main content
Geppetto Luis
Legend
July 6, 2018
Resuelto

Selezionare Sampled Colors

  • July 6, 2018
  • 2 respuestas
  • 1371 visualizaciones

There is a script to select color range items

Sampled colors

as in picture

Este tema ha sido cerrado para respuestas.
Mejor respuesta de r-bin

You can try this method.

Works in CC2018, but for some reason it does not work in CS6.

The method is based on creating and using a temporary preset file for the Color Range.

var c = new SolidColor();

//c.lab.l = 1;

//c.lab.a = 2;

//c.lab.b = 3;

color_range(c, 50, true);

/////////////////////////////////////////////////////////////////////////////////////

function color_range(color, fzns, dlg)

    {

    var file = new File(Folder.temp.fsName + "\\" + "_TMP_");

    try {

        var l = Math.round(0x8000 * color.lab.l/100);           

        var a = Math.round(0x4000 + color.lab.a*128);           

        var b = Math.round(0x4000 + color.lab.b*128);           

        var f = Math.round(fzns*128.5);

        var l_min = l;

        var l_max = l;

        var a_min = a;

        var a_max = a;

        var b_min = b;

        var b_max = b;

        var data = word(2) + word(6) + // something like the type and version of the file

            dword(l_min) + dword(l_max) +

            dword(a_min) + dword(a_max) +

            dword(b_min) + dword(b_max) +

            dword(f) +

            dword(0) + dword(0) + dword(0);

        file.open("w");

        file.encoding = "BINARY";

        file.write(data);

        file.close();

        var d = new ActionDescriptor();

        d.putPath(stringIDToTypeID("using"), file);

        executeAction(stringIDToTypeID("colorRange"), d, dlg?DialogModes.ALL:DialogModes.NO);

        }

    catch(e) { throw(e); }

    file.remove();

    function word(r)

        {

        var r1 = r%256;

        var r2 = ((r - r1)/256)%256;

        return String.fromCharCode(r2, r1);

        }

    function dword(r)

        {

        var r1 = r%256;

        var r2 = ((r - r1)/256)%256;

        var r3 = ((r - r1 - r2*256)/(256*256))%256;

        var r4 = ((r - r1 - r2*256 - r3*256*256)/(256*256*256))%256;

        return String.fromCharCode(r4, r3, r2, r1);

        }

    }

2 respuestas

r-binRespuesta
Legend
July 8, 2018

You can try this method.

Works in CC2018, but for some reason it does not work in CS6.

The method is based on creating and using a temporary preset file for the Color Range.

var c = new SolidColor();

//c.lab.l = 1;

//c.lab.a = 2;

//c.lab.b = 3;

color_range(c, 50, true);

/////////////////////////////////////////////////////////////////////////////////////

function color_range(color, fzns, dlg)

    {

    var file = new File(Folder.temp.fsName + "\\" + "_TMP_");

    try {

        var l = Math.round(0x8000 * color.lab.l/100);           

        var a = Math.round(0x4000 + color.lab.a*128);           

        var b = Math.round(0x4000 + color.lab.b*128);           

        var f = Math.round(fzns*128.5);

        var l_min = l;

        var l_max = l;

        var a_min = a;

        var a_max = a;

        var b_min = b;

        var b_max = b;

        var data = word(2) + word(6) + // something like the type and version of the file

            dword(l_min) + dword(l_max) +

            dword(a_min) + dword(a_max) +

            dword(b_min) + dword(b_max) +

            dword(f) +

            dword(0) + dword(0) + dword(0);

        file.open("w");

        file.encoding = "BINARY";

        file.write(data);

        file.close();

        var d = new ActionDescriptor();

        d.putPath(stringIDToTypeID("using"), file);

        executeAction(stringIDToTypeID("colorRange"), d, dlg?DialogModes.ALL:DialogModes.NO);

        }

    catch(e) { throw(e); }

    file.remove();

    function word(r)

        {

        var r1 = r%256;

        var r2 = ((r - r1)/256)%256;

        return String.fromCharCode(r2, r1);

        }

    function dword(r)

        {

        var r1 = r%256;

        var r2 = ((r - r1)/256)%256;

        var r3 = ((r - r1 - r2*256)/(256*256))%256;

        var r4 = ((r - r1 - r2*256 - r3*256*256)/(256*256*256))%256;

        return String.fromCharCode(r4, r3, r2, r1);

        }

    }

Geppetto Luis
Legend
July 9, 2018

r-bin

a great job

unfortunately after using it the first time

if I try to open color range from the menu I get an error

and it does not keep me going

this is the error

Legend
July 9, 2018

Very strange. On Windows all is OK.

Try commenting out or deleting the line

file.remove(); 

and run the script at least once and click OK.

Geppetto Luis
Legend
July 8, 2018

Maybe I mistreated the request

in the past I have asked for this help

create selection with color sampler

https://forums.adobe.com/message/10014373#10014373

Which for my needs is fine

with photoshop cc2014

unfortunately with photoshop cc2018 is not good

I have to manually set it in the color range window

sampled color

as in the screenshot above

there is a way to automatically set the sampled color

without that every time I have to set it manually.

Kukurykus
Legend
July 8, 2018

I tried c.pfaffenbichler script and it works without showing Color Range Palette in CC 19.1.5 with up to 10 Color Samplers.

Geppetto Luis
Legend
July 8, 2018

It should not open the color sampler window

but if the window is set to a color the script will not work properly

and does not take into account the sampled points