Copy link to clipboard
Copied
I have a need and I do not know if it's possible
I would like to create a gradient map from swatches
Copy link to clipboard
Copied
from two, three, four, five … swatches - or from all swatches?
Can you show/give an example file?
Copy link to clipboard
Copied
If I can choose and better.
Copy link to clipboard
Copied
probably minimum and possible maximum?
Copy link to clipboard
Copied
minimum 3 maximum 10,
Copy link to clipboard
Copied
​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.
Copy link to clipboard
Copied
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!")
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
Tom you're right
I apologize for exaggerating requests.
Copy link to clipboard
Copied
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); }
}
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
Maybe I did something wrong but in CC2019 and CC2020 it stops at: d1.putDouble(stringIDToTypeID("red"), c.rgb.red);
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now