Bright red, Fuchsia and Mauve just won’t do. They need exacting names like: #FF0000, #FF00FF and #E0B0FF.
Since more and more folks are using Visio for prototyping web sites and user interfaces, I thought it might be useful to create a SmartShape that displays the hexadecimal color value for a particular shape.
I came up with this contraption a few months ago, but then David Parker went and wrote this rather similar post: Displaying the RGB values of Shapes, and I felt a bit sheepish about not getting this up on Visio Guy sooner.
A Visio SmartShape That Speaks Hexadecimal
The shape is quite simple to use. Just drag out a copy of it, give it a fill color, and Presto! You see the hexadecimal value of the color. It’s easy to check by using basic colors that have full red, green or blue components, like these:
If you’re not sure what the strange numbers mean, well FF is hexadecimal, or “base 16” for the number 255. The hexadecimal value is actually three values stuffed together. The left two digits represent the red-component of the color, the middle two are for green, and the last two are for blue. Each component can have a range from 0 to 255.
So you can see that red has the full red value, and 0 for green and blue. Yellow has the full value (FF) for both red and green, but no blue value.
Black, white and shades of grays are interesting, in that all three components are equal. To make a shade of gray, just make sure red = green = blue!
Using the Hex-color Shape
If you are laying out a user-interface in Visio, and come up with some color you like, just drag this shape into your drawing.
To pick up the color of some other shape, use the Format Painter tool to bring the colors into the Hex-color shape. Don’t worry if the font attributes for the hex-color shape change. The Format Painter has a way of “destroying” everything. What’s important is that you are able to detect the color. And those smarts will remain intact.
You can now just double-click the shape to select and copy the text for use in your other project!
How the Hex-color Visio Shape Works
If you’re into ShapeSheet development, you might be interested in how this thing works.
The intelligence behind this thing can be seen by looking at the User-defined cells section in the ShapeSheet. Take a quick look:
Although it looks daunting, you can see that the first six rows break down into three groups of two rows. Each set of rows deals with a different color component:
The R, G, B cells just get the individual red, green and blue components of the shape’s fill foreground color. These values are decimal, though, with possible values of 0-255.
Once we have the individual decimal values, we need to build two-digit hexadecimal values from them.
INT(User.R/16) gives us the left hexadecimal value, and MODULUS(User.R/16) gives us the right value (modulus returns the “remainder” of a division.) But these calculations still give us decimal values from 0 – 15. So we use the results of these two calculations to lookup the hexadecimal values stored in User.hexVals.
So let’s take the full shade of red, where the color can be defined as RGB(255,0,0).
User.R = 255
INT(255/16) = 15
MODULUS(255, 16) = 15
The INDEX function then looks for the fifteenth value in the list “0;1;2;3;4;5;6;7;8;9;A;B;C;D;E;F”. This gives us an F, which is used for both digits of the red color. Note that F is really the 16th item in the list, but the INDEX function is zero-based. So everything shifts by one, and F becomes the “15th” item in the list and 0 is the “oth” item, so to speak.
User.text just concatenates all of the r, g, b hex values together, with a leading “#”. This cell is then inserted as the text field for the shape, so you don’t have to dive into the ShapeSheet to see the result of all the calculations!
Get the Visio Hex-color Shape
You can download the stencil that contains the shape here:
Download “Visio Hex-color Shape Stencil”s!Aj0wJuswNyXlhkqdQ60Y53EWeEeF – Downloaded 4067 times – 103.00 B