Skip to main content
Participant
October 20, 2020
Question

Photoshop swatches to layers

  • October 20, 2020
  • 1 reply
  • 232 views

Hello all,

 

 

I have a swatch of 400+ colors and i ill need to render them on layers.Is there any method to do that, other one by one?

 

Thank you,

Flo

 

 

 

This topic has been closed for replies.

1 reply

Legend
October 20, 2020

Perhaps this script will solve your problem.

 

var fake_color = new SolidColor();

fake_color.cmyk.cyan    = 100;
fake_color.cmyk.magenta = 100;
fake_color.cmyk.yellow  = 100;
fake_color.cmyk.black   = 100;

var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var list = executeActionGet(r).getList(stringIDToTypeID("presetManager")).getObjectValue(1).getList(stringIDToTypeID("name"));

var color_names = new Array();

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

var i = 1;
var n = 0;

while (n < color_names.length)
    {
    app.foregroundColor = fake_color;

    var d = new ActionDescriptor();
    var r = new ActionReference();
    r.putIndex(stringIDToTypeID("colors"), i);
    d.putReference(stringIDToTypeID("null"), r);
    executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

    if (app.foregroundColor.cmyk.cyan != fake_color.cmyk.cyan || app.foregroundColor.cmyk.magenta != fake_color.cmyk.magenta || app.foregroundColor.cmyk.yellow != fake_color.cmyk.yellow || app.foregroundColor.cmyk.black != fake_color.cmyk.black)
        {
        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putClass(stringIDToTypeID("contentLayer"));
        d.putReference(stringIDToTypeID("null"), r);
        var d1 = new ActionDescriptor();
        d1.putString(stringIDToTypeID("name"), color_names[n]);
        var d2 = new ActionDescriptor();
        var d3 = new ActionDescriptor();
        d3.putDouble(stringIDToTypeID("red"),   app.foregroundColor.rgb.red);
        d3.putDouble(stringIDToTypeID("green"), app.foregroundColor.rgb.green);
        d3.putDouble(stringIDToTypeID("blue"),  app.foregroundColor.rgb.blue);
        d2.putObject(stringIDToTypeID("color"), stringIDToTypeID("RGBColor"), d3);
        d1.putObject(stringIDToTypeID("type"), stringIDToTypeID("solidColorLayer"), d2);
        d.putObject(stringIDToTypeID("using"), stringIDToTypeID("contentLayer"), d1);
        executeAction(stringIDToTypeID("make"), d, DialogModes.NO);

        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        d.putReference(stringIDToTypeID("null"), r);
        executeAction(stringIDToTypeID("selectNoLayers"), d, DialogModes.NO);

        ++n;
        }            

    ++i;
    }