Today, I was querying the properties of a color descriptor in a text style range and was pretty surprised by the output of the descriptor's keys:
Code: Select all key : red
type : DescValueType.DOUBLETYPE
key : grain
type : DescValueType.DOUBLETYPE
key : blue
type : DescValueType.DOUBLETYPE
red, grain, and blue? Is there some color terminology that I've never heard of or is grain really a mishap? Either way, the descriptor doesn't behave as I expect. If I query any one of the color channels they all return the exact same nine digit number...
Here is a code snippet example of what I'm talking about:
Code: Select all //Gets only the first style in the ActionList
var firstTextStyle = styleList.getObjectValue(0);
// Get an AM descriptor for the actual Styling properites
var firstTextStyleDesc = firstTextStyle.getObjectValue(stringIDToTypeID('textStyle'));
// Finally...Get the font name and Size for the textStyle Desc
textProperties.fontName = firstTextStyleDesc.getString(stringIDToTypeID('fontName'));
textProperties.fontSize = firstTextStyleDesc.getUnitDoubleValue(stringIDToTypeID('size'));
colorDesc = firstTextStyleDesc.getObjectValue(stringIDToTypeID('color'));
$.writeln(colorDesc.getUnitDoubleType(stringIDToTypeID('red')));
$.writeln(colorDesc.getUnitDoubleType(stringIDToTypeID('grain')));
$.writeln(colorDesc.getUnitDoubleType(stringIDToTypeID('red')));
And it writes out:
Code: Select all592342629
592342629
592342629
But I was expecting each to return it's respective values from 0-255. So, what am I doing wrong in pulling the color of specific textstyle in RGB or even hex format?
Thanks,
Russ
Getting a specific textstyle's font color
Getting a specific textstyle's font color
Try getUnitDoubleValue instead of getUnitDoubleType.
Getting a specific textstyle's font color
Also there are a couple of charIDs that map to more than one stringID. charIDToCharID('Grn "),stringIDToTypeID('green'), and stringIDToTypeID('grain') all map to the same typeID - 1198681632.
And you may want to get the object type for 'color'. The descriptors vary depending on the color mode of the document. The code you posted will fail if the document is not RGB.
And you may want to get the object type for 'color'. The descriptors vary depending on the color mode of the document. The code you posted will fail if the document is not RGB.
Getting a specific textstyle's font color
xbytor wrote:Try getUnitDoubleValue instead of getUnitDoubleType.
Wow, I didn't see that bug with countless read throughs...I feel a bit embarrassed, but it works. Thanks for the second pair of eyes xbytor.
Mike Hale wrote:And you may want to get the object type for 'color'. The descriptors vary depending on the color mode of the document. The code you posted will fail if the document is not RGB.
Darn, I knew this, but had forgotten. So I have a script that will print out a desc key:value structure, do you know a way to print all the different key names when you query the action reference? It probably returned "grain" because it's alphabetically first?
Mike Hale wrote:And you may want to get the object type for 'color'. The descriptors vary depending on the color mode of the document. The code you posted will fail if the document is not RGB.
Did not realize this. Your direction is very appreciated.
Russ
Wow, I didn't see that bug with countless read throughs...I feel a bit embarrassed, but it works. Thanks for the second pair of eyes xbytor.
Mike Hale wrote:And you may want to get the object type for 'color'. The descriptors vary depending on the color mode of the document. The code you posted will fail if the document is not RGB.
Darn, I knew this, but had forgotten. So I have a script that will print out a desc key:value structure, do you know a way to print all the different key names when you query the action reference? It probably returned "grain" because it's alphabetically first?
Mike Hale wrote:And you may want to get the object type for 'color'. The descriptors vary depending on the color mode of the document. The code you posted will fail if the document is not RGB.
Did not realize this. Your direction is very appreciated.
Russ