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

How can I get scripting access to color values in the indexed Color Table?

New Here ,
Nov 04, 2013 Nov 04, 2013

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!!

TOPICS
Actions and scripting

Views

2.4K

Translate

Translate

Report

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

correct answers 1 Correct answer

People's Champ , Nov 06, 2017 Nov 06, 2017

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 ("

...

Votes

Translate

Translate
Adobe
New Here ,
Nov 06, 2017 Nov 06, 2017

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

Screen Shot 2017-11-06 at 9.52.44 AM.png

Surely there has to be a way to access this value

Votes

Translate

Translate

Report

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 06, 2017 Nov 06, 2017

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");

    }

Votes

Translate

Translate

Report

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 Beginner ,
May 03, 2019 May 03, 2019

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

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