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

Swatches name from color values

Contributor ,
Sep 22, 2014 Sep 22, 2014

Copy link to clipboard

Copied

Hi all,

How can we get the swatch name from its color value?

I looked into the photoshop scripting APIs but couldn't find anything related to swatches.

Thanks for any help..

TOPICS
Actions and scripting

Views

2.0K

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
Adobe
Community Expert ,
Sep 22, 2014 Sep 22, 2014

Copy link to clipboard

Copied

How can we get the swatch name from its color value?

Please elaborate.

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
Contributor ,
Sep 23, 2014 Sep 23, 2014

Copy link to clipboard

Copied

Thanks for the reply,

. Swatch.JPG

Here is a swatch name 'RGB Green' with the color value rgb(0, 255, 0). Now what I want here is that, I have rgb() values and I want to get the name of the swatches that the document have corresponding to those rgb values.

Does it make sense?

Actually I have a selected object and I am getting its fill color and from that color value I want to get the swatch name if any.

Thanks..

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 Expert ,
Sep 23, 2014 Sep 23, 2014

Copy link to clipboard

Copied

I have rgb() values and I want to get the name of the swatches that the document have corresponding to those rgb values.

As far as I can tell Photoshop Documents don’t have Swatches, the Application does.

But semantics aside I suspect the task might be a problematic one.

Have you looked around on ps-script.com yet?

ps-scripts.com • View topic - Managing Color Swatches

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
Contributor ,
Sep 23, 2014 Sep 23, 2014

Copy link to clipboard

Copied

As far as I can tell Photoshop Documents don’t have Swatches, the Application does.

Sorry for my ignorance..

I had looked into it but I didn't find anything useful in their, related to my task..

Although It seems like there, we can get the list of swatches name and from the name we can get the color values. And after that I can match the values with the fill color of selected art object.

What I am looking here something like, set the rgb values in the keys and by using action manager code I can get the swatch name.

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 Expert ,
Sep 23, 2014 Sep 23, 2014

Copy link to clipboard

Copied

Using xbytor’s xtools’ Scripts "ColorSwatches.jsx" and "Stream.js" one can get a Swatch’s color, albeit … the Swatch is being identified by name and it seems possible to have more than one swatch with the same name in the Panel.

$.evalFile("/*insert the correct path here*/ColorSwatches.jsx");

$.evalFile("/*insert the correct path here*/Stream.js");

var theName = /*insert the name as a string here*/;

alert (ColorSwatches.getColor(theName).rgb.red+"_"+ColorSwatches.getColor(theName).rgb.green+"_"+ColorSwatches.getColor(theName).rgb.blue);

To get a list of the Swatches’ names one can use this:

// based on mike hale’s code;

var ref = new ActionReference();

ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var desc = executeActionGet(ref);// get the app descriptor

var presetsList = desc.getList(stringIDToTypeID('presetManager'));// the presets list

var swatchDesc = presetsList.getObjectValue(1);// swatches is the second key

var nameList = swatchDesc.getList(charIDToTypeID("Nm  "));// there is only one key in the swatch descriptor so get the list

var theNames = new Array;

for (var m = 0; m < nameList.count; m++) {

theNames.push(nameList.getString(m))

};

alert (theNames.join("\n"));

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
Contributor ,
Sep 23, 2014 Sep 23, 2014

Copy link to clipboard

Copied

Thanks for the help..

I will try it.

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 Expert ,
Sep 23, 2014 Sep 23, 2014

Copy link to clipboard

Copied

It would be a round-about way – getting the names, then using the names to get the colours, then comparing those to the Foreground Color (or whatever).

Hopefully someone else can offer more insight … but as you marked this thread as answered others may not pay it much mind so you might want to start a new thread if the method proves too cumbersome.

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 25, 2015 May 25, 2015

Copy link to clipboard

Copied

can get  any color swatches  color name and  color value by javascript?  xbytor’s xtools’ Scripts "ColorSwatches.jsx" and "Stream.js" can't run photoshop cc

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
Advocate ,
Dec 18, 2024 Dec 18, 2024

Copy link to clipboard

Copied

@c.pfaffenbichler 

I know its an old thread, but i was trying some of the code you pasted. I believe it contains errors. its asks for 

 

 

 

ColorSwatches.getColor

 

 

 

But since no color is added, it simply return undefined, its declared as a list, when _runtime starts. At least, thats how i think its working.  Unless   

 

 

 

self.colorsByName = {};

 

 

 

gets filed by some other script which is then missing 
I only see 

 

 

self.colorsByName

 

 

 being used, when a color is added by 

 

 

ColorSwatches.prototype.addColor

 

 

EDIT
Nevermind it does work, after checking, i was requesting wrong name. Thats why it returns undefined. Im going to add a catch for that. But it doesnt seem to like LAB or PMS colors. REturn work colortype.; 

ColorSwatches.LAB_TYPE are defined as index numbers, INT n umber. But Pantone names return 4 digit number?. Kinda weird

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
Advocate ,
Dec 19, 2024 Dec 19, 2024

Copy link to clipboard

Copied

@c.pfaffenbichler 

 

Could it be that due to the addition of being able to add folders and sub-folders now in the swatches. The original code tp read binary *.aco files does work properly?
I see there are functions in stream.js to read byte Data some are 'readInt16()', which read 'byt()'


Perhaps i just need to be bold and email him Not sure if he is still active or codes

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 Expert ,
Dec 19, 2024 Dec 19, 2024

Copy link to clipboard

Copied

You mean @xbytor ? 

I am not sure when I last saw of post of theirs. 

 

As for reading/interpreting the aco-files directly I am not able to help you. 

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
Advocate ,
Dec 19, 2024 Dec 19, 2024

Copy link to clipboard

Copied

LATEST

I mailed him/her

 

Well it seems, at least i think, it can not read pantone colors, even though they are basical stored as LAB values. If i make a PMS color with its lab values according to a color book file, it works. But a swatch file which has a pms color from a color book returns the error.

Hope he chime in

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