Copy link to clipboard
Copied
Hey all,
I'm relatively new to Photoshop scripting, but I've just finished a script that helps my fiance with some very tedious tasks related to textile design.
The last issue that I'm having is that the image I start with is indexed and has a very specific Color Table pallete ( 2-12 colors max + black and white, so 14 max total, sometimes as few as 2 ). Part of my script, I create a number of color chips and fill them with black currently... What I'd like is to be able to get a count of the colors in the Color Table and put the actual color values as hex into an 1 dimension array, so that I fill those black chips I've made with the actual colors from the Color Table.
( I don't know if it makes a difference but I'm converting the image to RGB mode at some point in the script, and back to Indexed Exact ).
Can anyone please help me do this? Needs to be compatible with CS5 and CS6 ideally.
Thanks!!
1 Correct answer
You can access the Color Table only in manual mode, Run this script and change at least one color in the table, Then you can get both the counter and the colors.
var d = new ActionDescriptor();
var r = new ActionReference();
r.putProperty( charIDToTypeID( "Clr " ), charIDToTypeID( "ClrT" ) );
d.putReference( charIDToTypeID( "null" ), r );
var ret = executeAction( charIDToTypeID( "setd" ), d, DialogModes.ALL );
if (ret.count)
{
var list = ret.getList(charIDToTypeID( "T " ));
alert ("
...Explore related tutorials & articles
Copy link to clipboard
Copied
I'm trying to do this as well and I noticed that there is an index value in the Info panel
Surely there has to be a way to access this value
Copy link to clipboard
Copied
You can access the Color Table only in manual mode, Run this script and change at least one color in the table, Then you can get both the counter and the colors.
var d = new ActionDescriptor();
var r = new ActionReference();
r.putProperty( charIDToTypeID( "Clr " ), charIDToTypeID( "ClrT" ) );
d.putReference( charIDToTypeID( "null" ), r );
var ret = executeAction( charIDToTypeID( "setd" ), d, DialogModes.ALL );
if (ret.count)
{
var list = ret.getList(charIDToTypeID( "T " ));
alert ("Count:" + list.count);
var str = "";
for (var i = 0; i < list.count; i++)
{
var obj = list.getObjectValue(i);
for (var n = 0; n < obj.count; n++)
{
str += n + " " + obj.getDouble(stringIDToTypeID("red")) + " " + obj.getDouble(stringIDToTypeID("green")) + " " + obj.getDouble(stringIDToTypeID("blue")) + "\n"
}
}
alert(str);
}
else
{
alert("Nothing changed");
}
Copy link to clipboard
Copied
Thank you very much r-bin​ for your code, really useful.
I'll try to access the color table in other ways and get back I succeed.

