johnvisiomvp

Life with Visio and other Microsoft Toys!

Colour My World

leave a comment »

When I was working on the Windows 7&8 phone apps I created a Visio template to help design phone apps. As usually, it was a Visio stencil that was a bit more than dragging and dropping clipart. One of the WP7 and WP8 features it replicated was accent colours that were set on the phone and were applied to the apps. If you changed the Accent colour any object that used the Accent colour would change.
The technique I used was based on a technique demonstrated by Mark Nelson. The original Visio was based on a palette of 24 colours that were enumerated 0 to 24. Mark’s technique used a Lookup formula in the colour cell that looked up the colour in a list. It basically used the list to find the index of the colour.
The instructions are to put this formula in the FillForegnd cell.
=Lookup(Prop.Status,”Black;White;Red;Green;Blue;Yellow”)
Lookup will match the value of the custom property (the old name for Shape Data) Status to the list shown above. The value returned by Lookup will be a number, starting with 0, which corresponds to the position of the matched value in the list. The list shows Visio’s numbering sequence for the first couple of colours. As I said, there were 24 originalcolours, So the list of colour string can be extended to add the missing colours.

If the Status property choices are “Warning”, “Caution” and “Clear”, in the Lookup formula, replace the words “Red”, “Yellow” and “Green” with “Warning”, “Caution” and “Clear”. You must leave the other colours in as place holders to get the correct colour position. Actually, you should keep the list of colours as a comment so that if you want add or change the colours or strings you have a template for their placement. The final formula would be:
=Lookup(Prop.Status,”Black;White;Warning;Clear;Blue;Caution”)

This is fine if the colours you want are in the original 24 colours of the Visio colour palette. Luckily Visio has been extended so in addition to the original colour names you can use a string in the colour cell as long as it evaluates to an RGB value. So now it is a matter of manipulating strings.
In Mark’s solution, everything was within one formula. The string manipulation will require a few more cells. So, what cells and where should they be placed? Most of the strings do not have to be available to the user, so User cells rather than Shape Data cells makes more sense. A Shape Data cell will be required to let the user choose the colour. In Visio there are three shapesheets that can be used. In addition to the shapes’s shapesheet there is a page and a document shapesheet. To reference the document stencil, precede the cell name with TheDoc! And use ThePage! As the prefix for the page. To actually access these shapesheets go to the Developer tab. There is a dropdown for each shapesheet on the ribbon. So why use them? If you have an item that is referenced several times on a page or many times in a document, placing it in the shapesheet with the appropriate scope makes sense. The value is in one location and maintenance is reduced. Do you really want to be hunting through a document to find out where a list is used to change a value? Use a reference and keep a single copy of the value.
So, to solve the limitation on colours, I create two user properties. Both were lists (Type 1 shape data). One list was the names and a the other was a matching list of the RGB values. I could have placed these values in the User Data section for the shape, but I placed them in the User data for the document. So any shape in the document could use these values. The difference between a User property and a shape data property is that the user property is hidden from the user.
I put the reference to an occurrence of the colour in the Page Shapesheet. So the control of the Accent colour is at the page level. So if I change the accent colour, all shapes on that page using an accent colour will change. I chose the page level because I may want to have different accent colours on different pages.
So, the Document shapesheet would have two user data cells:
User.WP7Colours =”Magenta;Purple;Teal;Lime;Brown;Pink;Mango;Blue;Red ;Green”

User.WP7ColoursRGB =”RGB(255,00,151);RGB(162, 00, 255);RGB(00, 171, 169);RGB(140,191, 38);RGB(153, 102,00); RGB(233,113,184);RGB(240, 150, 09);RGB(27, 161, 226);RGB(229, 20, 00);RGB(51, 153, 51)”

Or for the Windows phone 8 accent colours
User.WP8Colours =”Amber;Brown;Cobalt;Crimson;Cyan;Emerald;Green;Indigo;Lime;Magenta;Mauve;Olive; Orange;Pink;Red;Steel;Taupe;Teal;Violet;Yellow”

User.WP8ColoursRGB =”RGB(240,163,10);RGB(130,90,44);RGB(0,80,239);RGB(162,0,37);RGB(27,161,226); RGB(0,138,0);RGB(96,169,23);RGB(106,0,255);RGB(164,196,0);RGB(216,0,115);RGB(118,96,138);RGB(109,135,100); RGB(250,104,0);RGB(244,114,208);RGB(229,20,0);RGB(100,118,135);RGB(135,121,78);RGB(0,171,169);RGB(170,0,255); RGB(227,200,0)”

The Page shapesheet would have one user cell:
User.WP7AccentColour =INDEX(LOOKUP(Prop.WP7AccentColour,TheDoc!User.WP7Colours),TheDoc!User.WP7ColoursRGB)

Or for the Windows phone 8 accent colours
User.WP8AccentColour =INDEX(LOOKUP(Prop.WP8AccentColour,TheDoc!User.WP8Colours),TheDoc!User.WP8ColoursRGB)

And a Shape Data cell :
Prop.WP7AccentColour Type=1
Label = Accent Colour 7
Format =TheDoc!User.WP7Colours
Value =INDEX(5,Prop.WP7AccentColour.Format)
Or
Prop.WP8AccentColour Type=1
Label = Accent Colour 8
Format =TheDoc!User.WP8Colours
Value =INDEX(9,Prop.WP8AccentColour.Format)

In the actual shape shapesheet Fill Format section the FillForegnd cell would be ThePage!User.WP7AccentColour or ThePage!User.WP8AccentColour.

So if you need to add colour palettes to a shape or group of shapes you can create two lists, one for the name of the colour and the other the RGB values. Treating the colour as a string, create a shape data to hold the value and assign that string to the appropriate colour cell. Where you place the user cells or shape data cells is dependent on whether the colour palette is limited to a shape or to a page or a document.
I have added a sample Visio drawing in the Technet Gallery. https://gallery.technet.microsoft.com/Visio-Colour-picker-29158b2c

Enjoy…

John Marshall… Visio MVP Visio.MVPs.org

Advertisements

Written by johnvisiomvp

July 8, 2017 at 6:15 pm

Posted in Shapes, Uncategorized, Visio

Tagged with ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: