25 Replies Latest reply on Mar 7, 2017 6:16 AM by CoverBuilder

    Getting the ID and the RGB array for the tag color of a XML tag

    kapoor_aman27 Level 1

      I need to get the array of double values eg: (124,255,255) for the tag color applied on XML tag.

      Note that I need values for RGB color space only.

       

      var color = oXMLTag.tagColor;
      

      The above returned color is enumeration is most of the cases (RED,CYAN etc).

       

      How can I get the double values for this color also the color ID.

        • 2. Re: Getting the ID and the RGB array for the tag color of a XML tag
          CoverBuilder Level 1
          var color = getUIcolorValue(oXMLTag.tagColor);
          
          function getUIcolorValue(r){if(r.constructor===Array)return pColour;switch(String(r)){case"BLACK":return[0,0,0];case"BLUE":return[0,0,255];case"BRICK_RED":return[153,0,0];case"BROWN":return[153,51,0];case"BURGUNDY":return[153,0,51];case"CHARCOAL":return[171,163,181];case"CUTE_TEAL":return[130,207,194];case"CYAN":return[0,255,255];case"DARK_BLUE":return[0,0,135];case"DARK_GREEN":return[0,84,0];case"FIESTA":return[247,89,107];case"GOLD":return[255,153,0];case"GRASS_GREEN":return[153,204,0];case"GRAY":return[128,128,128];case"GREEN":return[79,255,79];case"GRID_BLUE":return[122,186,217];case"GRID_GREEN":return[156,222,156];case"GRID_ORANGE":return[255,181,107];case"LAVENDER":return[153,153,255];case"LIGHT_BLUE":return[79,153,255];case"LIGHT_GRAY":return[186,186,186];case"LIGHT_OLIVE":return[140,166,107];case"LIPSTICK":return[207,130,181];case"MAGENTA":return[255,79,25];case"OCHRE":return[153,102,0];case"OLIVE_GREEN":return[102,102,0];case"ORANGE":return[255,102,0];case"PEACH":return[255,153,153];case"PINK":return[255,153,204];case"PURPLE":return[102,0,102];case"RED":return[255,0,0];case"SULPHUR":return[207,207,130];case"TAN":return[204,153,102];case"TEAL":return[0,153,153];case"VIOLET":return[153,51,255];case"WHITE":return[255,255,255];case"YELLOW":return[255,255,79];default:return alert("Could not find UI colour called "+String(pColor)),[186,186,186]}}
          
          • 3. Re: Getting the ID and the RGB array for the tag color of a XML tag
            Laubender Adobe Community Professional & MVP

            Hi CoverBuilder,

            how did you gather the RGB values for the UIColors ?

             

            Thanks,
            Uwe

            • 4. Re: Getting the ID and the RGB array for the tag color of a XML tag
              CoverBuilder Level 1

              I measured each of the colours and hardcoded them in. See the getUIcolorValue function.

              • 5. Re: Getting the ID and the RGB array for the tag color of a XML tag
                Laubender Adobe Community Professional & MVP

                :-)
                Ok. I should have rephrased my question:


                How did you measure the UI Colors ?

                 

                I see two ways:

                1. Using the colors with guides and export to PDF including guides.

                2. Using the colors with conditional text and export to PDF.

                 

                Measuring can be done with Acrobat Pro or a rendered pixel image from the PDF with PhotoShop.

                Depending on our color management settings we could get RGB values in e.g. sRGB.

                 

                Regards,
                Uwe

                • 6. Re: Getting the ID and the RGB array for the tag color of a XML tag
                  CoverBuilder Level 1

                  I measured RGB values with Digital Colour Meter using Display native values. See screenshot attached. What are you worried about?

                   

                  Screen Shot 2017-02-05 at 4.39.57 pm.png

                  • 7. Re: Getting the ID and the RGB array for the tag color of a XML tag
                    Laubender Adobe Community Professional & MVP

                    Thank you, pointing at the Digital Color Meter.app with OSX.
                    I really appreciate that! Forgot about this tool…

                     

                    With Digital Color Meter there are several options to get color values.

                    Here the L*a*b* values I see on my color LCD monitor (MacBook Pro) from the Guides panel options in inDesign:

                    [0.00,127.00,127.00]

                     

                    DigitalColorMeter-UI-Color-Cyan.png

                    Depending on the monitor used (and its color settings) I assume one could see different values. However I can be wrong on this.
                    Also it's not clear from your code, if you picked your values from sRGB, Generic RGB, Adobe RGB or "Native Values" (my translation):

                     

                    DigitalColorMeter-4-options-for-RGB.png

                     

                    Back to that what the OP likes to do:

                    After picking a value and using it in InDesign it's not clear how it will be used by the OP.

                     

                    Will it be output "as is"?

                    To what?

                    sRGB, Adobe RGB, something else?

                     

                    Will it be converted to CMYK at one point in the workflow?


                    I think, simply having three values for RGB is not enough.

                    One has also to define what color profile is meant.

                     

                    Even if you see the same L*a*b* values as I do, what RGB values did you pick?

                     

                    sRGB ? :

                    [34,255,255]

                    sRGB.png

                     

                     

                    Adobe RGB ? :

                    [147,255,255]

                    AdobeRGB.png

                     

                    Generic RGB ? :

                    [43,255,255]

                    GenericRGB.png

                     

                     

                     

                    From the value for UIColors.CYAN you hard-coded in your array I think you picked from "Native Values":

                    [0,255,255]

                     

                    NativeValues-in-RGB.png

                     

                     

                    I'm not exactly sure what is meant by "Native Values".

                    There is no color profile I can associate the values with.

                     

                    Maybe it's not good to use RGB values?

                    Maybe its better to use L*a*b* values that will translated best using color management for UI colors?

                     

                    Regards,
                    Uwe

                    • 8. Re: Getting the ID and the RGB array for the tag color of a XML tag
                      Laubender Adobe Community Professional & MVP

                      Sorry.

                      In you answer you also mentioned that you picked the values of: "Display native values".

                      I did not get that after reading the first time…

                       

                      Now I think, we need some further information from the OP to see if the values will be the right ones for the intended purpose.

                      I'm not sure about that at all.

                       

                      Regards,
                      Uwe

                      • 9. Re: Getting the ID and the RGB array for the tag color of a XML tag
                        CoverBuilder Level 1

                        UIcolours are saved as RGB (That is how you would set a custom one) so this is the right format to save the colours.

                         

                        What is the intended purpose?

                        • 10. Re: Getting the ID and the RGB array for the tag color of a XML tag
                          Trevorׅ Adobe Community Professional

                          There's some alternative values here Web colors - Wikipedia

                          One could make a color chart on an SUI and drawing squares from the UIcolors, your values and Wikipedia values and compare them.

                          Sounds fun but I'll leave the pleasure for someone else.

                          • 11. Re: Getting the ID and the RGB array for the tag color of a XML tag
                            Laubender Adobe Community Professional & MVP

                            CoverBuilder wrote:

                            … What is the intended purpose?

                            Yes. That's the question the OP could answer.

                             

                            Regards,
                            Uwe

                            • 12. Re: Getting the ID and the RGB array for the tag color of a XML tag
                              Dirk Becker Level 4

                              From the plugin side, you can look up the colors using IUIColorUtils.

                              Unfortunately I got the name string only in its translated form, and had to leave the script enumerators as an exercise.

                              RGB values are provided in 0..1 range.

                              Note that the UI colors are internally just another swatch list that gets copied from application preferences to each document, and there are methods to modify them - don't know how you'd reach them thru scripting or the UI though.

                              While the above link is from the CS1 SDK documentation (only version that ever got online), the following list is from an early CC.2015.

                               

                              "Light Blue": { 0.310000, 0.600000, 1.000000 },

                              "Red": { 1.000000, 0.000000, 0.000000 },

                              "Green": { 0.310000, 1.000000, 0.310000 },

                              "Blue": { 0.000000, 0.000000, 1.000000 },

                              "Yellow": { 1.000000, 1.000000, 0.310000 },

                              "Magenta": { 1.000000, 0.310000, 1.000000 },

                              "Cyan": { 0.000000, 1.000000, 1.000000 },

                              "Gray": { 0.500000, 0.500000, 0.500000 },

                              "Black": { 0.000000, 0.000000, 0.000000 },

                              "Orange": { 1.000000, 0.400000, 0.000000 },

                              "Dark Green": { 0.000000, 0.330000, 0.000000 },

                              "Teal": { 0.000000, 0.600000, 0.600000 },

                              "Tan": { 0.800000, 0.600000, 0.400000 },

                              "Brown": { 0.600000, 0.200000, 0.000000 },

                              "Violet": { 0.600000, 0.200000, 1.000000 },

                              "Gold": { 1.000000, 0.600000, 0.000000 },

                              "Dark Blue": { 0.000000, 0.000000, 0.530000 },

                              "Pink": { 1.000000, 0.600000, 0.800000 },

                              "Lavender": { 0.600000, 0.600000, 1.000000 },

                              "Brick Red": { 0.600000, 0.000000, 0.000000 },

                              "Olive Green": { 0.400000, 0.400000, 0.000000 },

                              "Peach": { 1.000000, 0.600000, 0.600000 },

                              "Burgundy": { 0.600000, 0.000000, 0.200000 },

                              "Grass Green": { 0.600000, 0.800000, 0.000000 },

                              "Ochre": { 0.600000, 0.400000, 0.000000 },

                              "Purple": { 0.400000, 0.000000, 0.400000 },

                              "Light Gray": { 0.730000, 0.730000, 0.730000 },

                              "Charcoal": { 0.670000, 0.640000, 0.710000 },

                              "Grid Blue": { 0.480000, 0.730000, 0.850000 },

                              "Grid Orange": { 1.000000, 0.710000, 0.420000 },

                              "Fiesta": { 0.970000, 0.350000, 0.420000 },

                              "Light Olive": { 0.550000, 0.650000, 0.420000 },

                              "Lipstick": { 0.810000, 0.510000, 0.710000 },

                              "Cute Teal": { 0.510000, 0.810000, 0.760000 },

                              "Sulphur": { 0.810000, 0.810000, 0.510000 },

                              "Grid Green": { 0.610000, 0.870000, 0.610000 },

                              "White": { 1.000000, 1.000000, 1.000000 }

                              • 13. Re: Getting the ID and the RGB array for the tag color of a XML tag
                                [Jongware] Most Valuable Participant

                                All UI colors are also always stored in every document(1) (in RGB, not as floats). I could take a look but I am certain someone else did this long ago and posted them on the web, and it should be easy googleable.

                                 

                                ((1) One wonders why. It's not as if these built-in colors can be adjusted. User defined colors are stored separately.)

                                • 14. Re: Getting the ID and the RGB array for the tag color of a XML tag
                                  Trevorׅ Adobe Community Professional

                                  I could not find the RGB values in a document but having the computer do (255 * x) | 0 was not tough. Nor was converting Brick Red to BRICK_RED.

                                  Here's my version based on Dirks figures.

                                   

                                  function uiToRgb(uiColor) {
                                      var uiColors = {'BLACK': [0, 0, 0], 'BLUE': [0, 0, 255], 'BRICK_RED': [153, 0, 0], 'BROWN': [153, 51, 0], 'BURGUNDY': [153, 0, 51], 'CHARCOAL': [170, 163, 181], 'CUTE_TEAL': [130, 206, 193], 'CYAN': [0, 255, 255], 'DARK_BLUE': [0, 0, 135], 'DARK_GREEN': [0, 84, 0], 'FIESTA': [247, 89, 107], 'GOLD': [255, 153, 0], 'GRASS_GREEN': [153, 204, 0], 'GRAY': [127, 127, 127], 'GREEN': [79, 255, 79], 'GRID_BLUE': [122, 186, 216], 'GRID_GREEN': [155, 221, 155], 'GRID_ORANGE': [255, 181, 107], 'LAVENDER': [153, 153, 255], 'LIGHT_BLUE': [79, 153, 255], 'LIGHT_GRAY': [186, 186, 186], 'LIGHT_OLIVE': [140, 165, 107], 'LIPSTICK': [206, 130, 181], 'MAGENTA': [255, 79, 255], 'OCHRE': [153, 102, 0], 'OLIVE_GREEN': [102, 102, 0], 'ORANGE': [255, 102, 0], 'PEACH': [255, 153, 153], 'PINK': [255, 153, 204], 'PURPLE': [102, 0, 102], 'RED': [255, 0, 0], 'SULPHUR': [206, 206, 130], 'TAN': [204, 153, 102], 'TEAL': [0, 153, 153], 'VIOLET': [153, 51, 255], 'WHITE': [255, 255, 255], 'YELLOW': [255, 255, 79]};
                                      return uiColor instanceof Array && uiColor || uiColors[uiColor] || "Don't know";
                                  }
                                  
                                  $.writeln(uiToRgb(5)); // => "Don't know"
                                  $.writeln(uiToRgb([1, 2, 3])); // => [1,2,3]
                                  $.writeln(uiToRgb(UIColors.OLIVE_GREEN)); // => [102, 102, 0]
                                  

                                   

                                  Trevor

                                  • 17. Re: Getting the ID and the RGB array for the tag color of a XML tag
                                    Trevorׅ Adobe Community Professional

                                    (255 * x) | 0 is the same as Math.floor(255 * x) not too readable but quick to type

                                    • 18. Re: Getting the ID and the RGB array for the tag color of a XML tag
                                      [Jongware] Most Valuable Participant

                                      No surprises here: I finally found the reference I was thinking of, and not only was it on this same forum, I even answered it

                                       

                                      Is it possible to extract the colors in the preferences?

                                       

                                      The link in it is no longer valid and not stored in the Wayback Machine either, but fortunately I added the relevant codes in a follow-up.

                                      • 19. Re: Getting the ID and the RGB array for the tag color of a XML tag
                                        CoverBuilder Level 1

                                        Haha, that is cool. Well you have answered an awful lot of posts!

                                        Good you remembered it

                                         

                                        Unfortunately it seems those values are measured from a screenshot too.

                                        I am kind of interested to find out how to get the values that are suposidly stored in the doc.

                                        But have not enough time to open this door of curiosity.

                                         

                                        Again, still not sure why anyone would even care if it is [79,152,255] or [79,153,255]?

                                        • 20. Re: Getting the ID and the RGB array for the tag color of a XML tag
                                          CoverBuilder Level 1

                                          Wow, that is pretty cool. I did not notice the single bar, I read it as OR not BINARY OR!

                                          I am a bit shady on bitwise operators and never use them. Thanks for pointing it out to me. I rather enjoyed this fact.

                                          • 21. Re: Getting the ID and the RGB array for the tag color of a XML tag
                                            [Jongware] Most Valuable Participant

                                            CoverBuilder wrote:

                                             

                                            Unfortunately it seems those values are measured from a screenshot too.

                                            I am kind of interested to find out how to get the values that are suposidly stored in the doc.

                                            But have not enough time to open this door of curiosity.

                                            It's inside one of the objects of the file database, and so not that easy to get a hold of. I'll take a peek and see if the values are very different from what has been posted so far.

                                            Again, still not sure why anyone would even care if it is [79,152,255] or [79,153,255]?

                                            Now that is a matter of principle . Well, that, and the fact that measuring from a screen is a bit unreliable. It's possible that the on screen color was already adjusted for a certain display (sRGB vs. Apple RGB, or even a fully custom monitor conversion). When displayed on your screen, again, it goes through a second translation, and so it may be more off than a single digit.

                                             

                                            Reading the raw "actual" values out of the software ensures that the color in your script will be the exact same color as in the UI itself.

                                            (Except when you use it in a document and view that in CMYK mode, or with a different color profile. But in scripts, at least, the colors should be the same.)

                                            • 22. Re: Getting the ID and the RGB array for the tag color of a XML tag
                                              Laubender Adobe Community Professional & MVP

                                              Hi Jongware,

                                              if we take the percentage values Dirk posted and do our math on it to translate them to the range of 0-255, we can see that Mac OSX Digital Color Meter app will show the rounded values with its "Native Values" option.

                                               

                                              Now it depends how someone likes to use the values.

                                               

                                              1. If I would build a UI with ScriptUI I would go for the RGB "Native Values".

                                               

                                              2. If I would like to use them with e.g. PhotoShop images or InDesign page items I would use either:

                                               

                                              A. Use the L*a*b* values offered by Digital Color Meter app and convert to my desired color space.

                                              B. Use the sRGB values or AdobeRGB values offered by Digital Color Meter app and tag my images accordingly.


                                              Or, in case of graphic frames etc. colored with the values in InDesign, I would use sRGB values or AdobeRGB values and define the working or document color space accordingly.

                                               

                                              Regards,
                                              Uwe

                                              • 23. Re: Getting the ID and the RGB array for the tag color of a XML tag
                                                Laubender Adobe Community Professional & MVP

                                                Btw. our OP kapoor_aman did not come back to comment our findings…
                                                I'd be glad if I knew what is the whole purpose of this all.

                                                 

                                                Regards,
                                                Uwe

                                                • 24. Re: Getting the ID and the RGB array for the tag color of a XML tag
                                                  kapoor_aman27 Level 1

                                                  Hi Laubender I went through the comments and seems there is a lot of useful information here. Fortunately, I found another solution to my problem which did not require finding the double values for standard color enumerators.

                                                  I am sure other's can benefit from this discussion.

                                                  • 25. Re: Getting the ID and the RGB array for the tag color of a XML tag
                                                    CoverBuilder Level 1

                                                    I suggest you post your solution here and mark it correct.