Copy link to clipboard
Copied
I'm trying to write a script that will take all the colors (using 0-threshold) in the current document found in the first .aso (the swatches of which are sorted in a specific order) and replaces them with the colors from the second swatch. So for example, if I wanted make a darker version of my image, I'd make one palette with #FF0000 red as the first swatch, #0000FF blue as the second swatch, etc, and in the second palette, I'd have dark red as the first swatch, and dark blue as the second swatch, etc. Then all instances of red in the file would be replaced with dark red, all instances of blue with dark blue, etc. And to complicate things further, the files have a timeline, so this would have to be done on every layer on every frame.
Is there a way to do this? Can I read hex colors from an *.aso file? Or will I have to store the colors in another format, like a text file? Is there a way to replace colors on every frame?
Try this script.
Change the code after the comment
// I did not understand what you really need
...var file1 = new File("C:/A0/1.aco"); // first color file // comment this line if you want to use the current color
var file2 = new File("C:/A0/2.aco"); // second color file
var file3 = new File("C:/A0/3.aco"); // result color file
var c1 = new Array();
var c2 = new Array();
///////////////////////////////////////////////////////////////////////////////
// Load the colors from file1 and save them in array c1
///
Copy link to clipboard
Copied
Try this script.
Change the code after the comment
// I did not understand what you really need
var file1 = new File("C:/A0/1.aco"); // first color file // comment this line if you want to use the current color
var file2 = new File("C:/A0/2.aco"); // second color file
var file3 = new File("C:/A0/3.aco"); // result color file
var c1 = new Array();
var c2 = new Array();
///////////////////////////////////////////////////////////////////////////////
// Load the colors from file1 and save them in array c1
///////////////////////////////////////////////////////////////////////////////
load_colors(file1); // comment this line if you want to use the current color
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"));
for (var i = 0; i < list.count; i++)
{
var c = get_color(i);
if (!c) break;
c1.push([c, list.getString(i)]);
}
///////////////////////////////////////////////////////////////////////////////
// Load the colors from file1 and save them in array c2
///////////////////////////////////////////////////////////////////////////////
load_colors(file2);
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"));
for (var i = 0; i < list.count; i++)
{
var c = get_color(i);
if (!c) break;
c2.push([c, list.getString(i)]);
}
///////////////////////////////////////////////////////////////////////////////
// Remove all curent colors
///////////////////////////////////////////////////////////////////////////////
for (var i = list.count-1; i >= 0; i--) del_color(i);
///////////////////////////////////////////////////////////////////////////////
// Create new colors based on colors from array c2 and c1
///////////////////////////////////////////////////////////////////////////////
for (var i = 0; i < c2.length; i++)
{
var c = c2[0];
var nm = c2[1];
// Do some colors modifications
// I did not understand what you really need
c.rgb.red = c.rgb.red/2;
new_color(c, nm);
}
///////////////////////////////////////////////////////////////////////////////
// Save the colors to file3
///////////////////////////////////////////////////////////////////////////////
if (file3.exists) file3.remove();
save_colors(file3)
///////////////////////////////////////////////////////////////////////////////
// End of script
///////////////////////////////////////////////////////////////////////////////
alert ("Done!");
///////////////////////////////////////////////////////////////////////////////
function load_colors(file)
{
try {
var d = new ActionDescriptor();
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("colors"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("null"), r);
d.putPath(stringIDToTypeID("to"), file);
d.putBoolean(stringIDToTypeID("append"), false);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
}
catch (e) { throw(e); }
}
///////////////////////////////////////////////////////////////////////////////
function save_colors(file)
{
try {
var d = new ActionDescriptor();
d.putPath(stringIDToTypeID("null"), file);
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("colors"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("to"), r);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
}
catch (e) { throw(e); }
}
///////////////////////////////////////////////////////////
function get_color(i)
{
try {
var c0 = app.foregroundColor;
var d = new ActionDescriptor();
var r = new ActionReference();
r.putIndex(stringIDToTypeID("colors"), i+1);
d.putReference(stringIDToTypeID("null"), r);
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
var c = app.foregroundColor;
app.foregroundColor = c0;
return c;
}
catch (e) { return null; }
}
///////////////////////////////////////////////////////////
function del_color(i)
{
try {
var d = new ActionDescriptor();
var r = new ActionReference();
r.putIndex(stringIDToTypeID("colors"), i+1);
d.putReference(stringIDToTypeID("null"), r);
executeAction(stringIDToTypeID("delete"), d, DialogModes.NO);
return true;
}
catch (e) { return false; }
}
///////////////////////////////////////////////////////////////////////////////
function new_color(c, name)
{
try {
var d = new ActionDescriptor();
var r = new ActionReference();
r.putClass(stringIDToTypeID("colors"));
d.putReference(stringIDToTypeID("null"), r);
var d1 = new ActionDescriptor();
d1.putString(stringIDToTypeID("name"), name);
var d2 = new ActionDescriptor();
d2.putDouble(stringIDToTypeID("red"), c.rgb.red);
d2.putDouble(stringIDToTypeID("green"), c.rgb.green);
d2.putDouble(stringIDToTypeID("blue"), c.rgb.blue);
d1.putObject(stringIDToTypeID("color"), stringIDToTypeID("RGBColor"), d2);
d.putObject(stringIDToTypeID("using"), stringIDToTypeID("colors"), d1);
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
}
catch (e) { throw(e); }
}
Copy link to clipboard
Copied
I should add that I mistakenly called them aso files when they're aco files, but as for your script, this goes a long way towards getting me where I want to go. Thanks!
Copy link to clipboard
Copied
Hi rbin, I tried running the code, but am getting this error:
the line "set" is not currently available
line: 94