8 Replies Latest reply on Nov 7, 2013 11:52 PM by KristofJanezic

    RGB values to Background color

    flovelett

      Title

      RGB values to Background color

      Post

           I'm a novice FM user with little or no scripting experience. I'm designing a database to keep track of color samples.

           Each record has 3 numeric fields with RGB values. I need a script that will pass these values on to define the fill color of an object in the layout so that a small color swatch will be displayed. Ideally the script should be designed so that if the RGB fields values are changed, that the object color will update.

           The FM reference shows that there is an RGB function, but I don't know how to use it to set the color of a layout object.

           Help greatly appreciated.

           Felicia

        • 1. Re: RGB values to Background color
          philmodjunk

               The RGB function is used to style text with a specific color by using it nested inside a function call to TextColor. It cannot be used to produce a specific fill color.

          • 2. Re: RGB values to Background color
            schamblee

                 Here is a sample I created that uses the webviewer to display a color swatch.  This sample uses two custom functions to convert decimals to hexadecimals and both functions were obtained from www.brianDunning.com

            https://www.sugarsync.com/pf/D9559058_78149901_131461

            • 3. Re: RGB values to Background color
              raybaudi

                   You could use a Web Viewer, as Chamblee said.
                   But I do not see why you'll need a Custom Function because you could simply set it to:

                   "data:text/html,
                   <html>
                   <body margin='0' style=border:'0' bgcolor=rgb(" &
                   YourTable::red
                   & "," &
                   YourTable::green
                   & "," &
                   YourTable::blue 
                   & ")>
                   </body>
                   </html>"

                   where red, green and blue are the names of your 3 fields.

              • 4. Re: RGB values to Background color
                flovelett

                     Thanks everyone for helping this strictly paste & pray coder!

                     raybaudi's no-custom-function solution worked fine as soon as I figured what I needed to replace "YourTable" with :/

                     Tried Chamblee's custom function route as well, but could not get this to work.

                       
                1.           Copied both custom functions, HTML code & created the calculated field Hex.
                2.      
                3.           Plugged in my RGB field names & my file name directory for container.
                4.      
                5.           Result: Hex field didn't get any values.

                     Would like to understand why this didn't work...might need to use a custom function someday.
                      

                • 5. Re: RGB values to Background color
                  schamblee

                       You need advance to create custom functions.  File, Manage, Custom functions.  You can import the function from the sample into your own databases, and you also can copy the hex calculation field from the sample database.   You don't have to use a custom function.  Three are many way to do things.  The contact starter solution uses custom functions for the google maps, but it can be done without.  I was making a sample to show how it could be done.  

                  • 6. Re: RGB values to Background color
                    KristofJanezic

                         I posted a similar problem and an answer led me to this. This is awesome! I have been trying to make this happen for a while, but do not know any HTML, so this is a great start. But I am having trouble with making this do exactly what I need it to. There is just one problem, and it's kind of weird.

                         In my use for this, I need for the 3 fields when at full (FF or 255) are black, and when out (00 or 0) are white, so that when red is at full it is full on red in the viewer and so on and so forth. At the moment, for whatever reason, the colors are completely off. For instance, when the red is at 255 it's a very dark green, and for whatever reason when all 3 are at 00 or FF instead of 0 or 255 the viewer goes red. I've double checked the code to make sure that the red green and blue fields are correctly placed according to your code. Is there any way to fix this?

                         And one more question, is it all possible to make the color extend to the edge of the web viewer without making the fill "none" so that the color itself can have curved corners?

                         any and all help is much appreciated! Thank you!

                          

                    Update: I got it working to give the correct colors, but I am stuck on making it on a subtractive color wheel within the web viewer. Also, the information I have is in a percentage form on an excel document. Is there any way to convert the percentage into the HTML color code?

                    • 7. Re: RGB values to Background color
                      flovelett

                           To Chamblee: Finally got you solution working as well. It's useful to know several approaches.

                           My mistake was to define the Hex field type as "text" and paste the calculation into the field options.

                           Once I changed the Hex field type to "calculation", the RGB values were passed along.

                           The Web Viewer works whether the Hex field calculation result is set to either number or text.

                           Thanks again so much!

                      • 8. Re: RGB values to Background color
                        KristofJanezic

                             I figured it out as well! It was actually really easy, just a second red/green/blue field that multiplied the decimal to an RGBdecimal which was then used in Chamblee's custom function to be put into HexDecimal format. Using that I can now have an archive of all the colors from different gel manufacturers and change the color of a web view based on the value of a field that pulls from that archive.

                             Both methods worked for the web viewer, by the way. I liked working with custom functions a little.

                             Thank you! This was an amazing help!