Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Create gradient map from swatches

Advocate ,
Nov 24, 2018 Nov 24, 2018

I have a need and I do not know if it's possible

I would like to create a gradient map from swatches

2.jpg @ 4,96% (RGB:8) * 2018-11-24 18-33-48.png

TOPICS
Actions and scripting
3.7K
Translate
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 Expert ,
Nov 24, 2018 Nov 24, 2018

from two, three, four, five … swatches - or from all swatches?

Can you show/give an example file?

Translate
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
Advocate ,
Nov 24, 2018 Nov 24, 2018

If I can choose and better.

Translate
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
Community Expert ,
Nov 24, 2018 Nov 24, 2018

probably minimum and possible maximum?

Translate
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
Advocate ,
Nov 24, 2018 Nov 24, 2018

minimum 3 maximum 10,

Translate
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
Community Expert ,
Nov 26, 2018 Nov 26, 2018

​Yes, you can add a gradient fill or a gradient map in Photoshop with AM-code. But IMO you don't get access to your swatches color. (in the past xTools was an alternative)

A little help you will find in this thread: ​Create Gradients with Custom Step Number & Color ...

The colors are hardcoded in these samples.

Maybe someone else will have better news for you.

Translate
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
People's Champ ,
Nov 26, 2018 Nov 26, 2018

I accidentally found a way to get color from color swatches.

But I do not think that this will help in this incomprehensible task.

Do not press Ctrl-key before and during the execution of the script.

var c1 = app.foregroundColor;

for (var i = 1;;i++)

    {

    var d = new ActionDescriptor();

    var r = new ActionReference();

    r.putIndex(stringIDToTypeID("colors"), i);

    d.putReference(stringIDToTypeID("null"), r);

    try { executeAction(stringIDToTypeID("select"), d, DialogModes.NO); } catch(e) { break; }

    var c = app.foregroundColor;

    app.foregroundColor = c1;

    alert("Swatch " + i+ "\n\n#" + c.rgb.hexValue);

    }

   

alert(i + " Done!")

Translate
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
Community Expert ,
Nov 26, 2018 Nov 26, 2018

Interesting!

works properly in CC 2019 but change only the background color (and give always back the same value for the foreground color) in CC 2017

Translate
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
People's Champ ,
Nov 26, 2018 Nov 26, 2018

It depends which color is set on the Color panel to be active, foreground or background.
Pressing Ctrl changes the inactive color with the "select" command.

In general, the method is a bit dumb.

Translate
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
Community Expert ,
Nov 26, 2018 Nov 26, 2018

You are totally right.

Normally I always have the foreground color in colors palette activ. But I 'played' with this setting just in the CC2017 version a few days ago to answer this thread with some screenshots: Re: Color Nonsense (I need help)

Back to standard and your snippet in CC2017 also works as expected.

Translate
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
Advocate ,
Nov 27, 2018 Nov 27, 2018

Sig r-bin

the script gives me the numerical value of each color

I would like the colors to create a gradient map

with the values created as in the figure

uio.jpg

Translate
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
Advocate ,
Nov 27, 2018 Nov 27, 2018

I think everyone has understood what you want.

You got the relevant informations and all you have to do is join them together.

The task of this forum isn't to create finished scripts on request (that would be the function for a paid job).

Translate
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
Advocate ,
Nov 27, 2018 Nov 27, 2018

Tom you're right

I apologize for exaggerating requests.

Translate
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
People's Champ ,
Nov 27, 2018 Nov 27, 2018

Haha, I finally got to CC2018.

And here it is.

var r = new ActionReference();

r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("MRUColorList"));

r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var list = executeActionGet(r).getList(stringIDToTypeID("MRUColorList")); 

var colors = new Array();

for (var i = 0; i < list.count; i++)

    {

    var d = list.getObjectValue(i);

    var c = new SolidColor();

   

    switch (list.getClass(i))

        {

        case stringIDToTypeID("RGBColor"):

            c.rgb.red   = d.getDouble(stringIDToTypeID("red"));

            c.rgb.green = d.getDouble(stringIDToTypeID("green"));

            c.rgb.blue  = d.getDouble(stringIDToTypeID("blue"));

            break;

        case stringIDToTypeID("grayscale"):

            c.gray.gray   = d.getDouble(stringIDToTypeID("gray"));

            break;

        case stringIDToTypeID("CMYKColorClass"):

            c.cmyk.cyan    = d.getDouble(stringIDToTypeID("cyan"));

            c.cmyk.magenta = d.getDouble(stringIDToTypeID("magenta"));

            c.cmyk.yellow  = d.getDouble(stringIDToTypeID("yellowColor"));

            c.cmyk.black   = d.getDouble(stringIDToTypeID("black"));

            break;

        case stringIDToTypeID("labColor"):

            c.lab.l = d.getDouble(stringIDToTypeID("luminance"));

            c.lab.a = d.getDouble(stringIDToTypeID("a"));

            c.lab.b = d.getDouble(stringIDToTypeID("b"));

            break;

        default:

            alert("unsupported color: " + typeIDToStringID(list.getClass(i)));

        }

    colors.push(c);

    }

make_gmap(colors);

function make_gmap(c)

    {

    try {

        var d = new ActionDescriptor();

        var r = new ActionReference();

        r.putClass(stringIDToTypeID("adjustmentLayer"));

        d.putReference(stringIDToTypeID("null"), r);

        var d1 = new ActionDescriptor();

        var d2 = new ActionDescriptor();

        var d3 = new ActionDescriptor();

        d3.putString(stringIDToTypeID("name"), "Gradient Map from Swatches");

        d3.putEnumerated(stringIDToTypeID("gradientForm"), stringIDToTypeID("gradientForm"), stringIDToTypeID("customStops"));

        d3.putDouble(charIDToTypeID("Intr"), 4096);

        var list = new ActionList();

        function put_color(loc, c)

            {

            var d = new ActionDescriptor();

            var d1 = new ActionDescriptor();

            d1.putDouble(stringIDToTypeID("red"),   c.rgb.red);

            d1.putDouble(stringIDToTypeID("green"), c.rgb.green);

            d1.putDouble(stringIDToTypeID("blue"),  c.rgb.blue);

            d.putObject(stringIDToTypeID("color"), stringIDToTypeID("RGBColor"), d1);

            d.putEnumerated(stringIDToTypeID("type"), stringIDToTypeID("colorStopType"), stringIDToTypeID("userStop"));

            d.putInteger(stringIDToTypeID("location"), loc);

            d.putInteger(stringIDToTypeID("midpoint"), 50);

            list.putObject(stringIDToTypeID("colorStop"), d);

            }

        for (var i = 0; i < c.length; i++) put_color(Math.round(4096*i/(c.length-1)), c);

        d3.putList(stringIDToTypeID("colors"), list);

        d2.putObject(stringIDToTypeID("gradient"), stringIDToTypeID("gradientClassEvent"), d3);

        d1.putObject(stringIDToTypeID("type"), stringIDToTypeID("gradientMapClass"), d2);

        d1.putString(stringIDToTypeID("name"), "Gradient Map from Swatches");

        d.putObject(stringIDToTypeID("using"), stringIDToTypeID("adjustmentLayer"), d1);

        executeAction(stringIDToTypeID("make"), d, DialogModes.NO);

        }

    catch (e) { alert(e); }

    }

Translate
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
Guide ,
Nov 28, 2018 Nov 28, 2018

You might like to add....

case stringIDToTypeID("HSBColorClass"):

     c.hsb.hue = d.getDouble(charIDToTypeID("H   "));

     c.hsb.saturation = d.getDouble(charIDToTypeID("Strt"));

     c.hsb.brightness = d.getDouble(charIDToTypeID("Brgh"));

     break;

Translate
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
LEGEND ,
Feb 16, 2020 Feb 16, 2020
LATEST

Maybe I did something wrong but in CC2019 and CC2020 it stops at: d1.putDouble(stringIDToTypeID("red"),   c.rgb.red);

Translate
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
People's Champ ,
Nov 27, 2018 Nov 27, 2018

You want to access recent colors.

Besides the fact that this feature is available only in the CC version, I still do not know how to get to these colors.

Translate
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