Development

Tips & code for programming Visio & using the ShapeSheet

Maps & Geography

Maps & geography shapes & templates galore!

Network

Shapes & tools for Visio network diagrams.

News

Find out what’s new in the Visio world!

Shapes

Download useful & attractive Visio shapes. For free!

where can i buy windows 7 cheapest buy windows 7 upgrade from xp windows vista purchase price buy inventor 2010 pctools spyware doctor 5.5 buy windows 7 best price norton ghost 12 product key windows 7 price future shop windows xp price singapore windows 2008 web server download omnipage coupon buy windows 7 starter download adobe indesign cs3 for mac buy vista to windows 7 microsoft project 2003 download buy windows xp operating system windows 7 home premium cheap mathcad pricing photoshop buy mac discount autocad 2009 purchase microsoft money 2007 deluxe download photoshop mac autodesk maya 2009 price windows vista business download windows 7 price 64 bit purchase windows 7 ultimate full version buy windows 7 home premium key lightroom for apple purchase windows xp india adobe cs4 photoshop buy where to buy encarta 2009 purchase vista oem buy windows 7 tesco cheap adobe fireworks windows 7 price online best price corel draw 11 mac discount powerpoint buy microsoft office for mac canada buy microsoft project 2002 adobe production premium mac turbotax 2009 deluxe best price windows 7 ultimate 64 bit best price buy windows 7 amazon adobe flash pricing adobe dreamweaver sale purchase windows 7 ultimate buy quickbooks pro 2007 roxio copy & convert 3 buy download photoshop elements 6 steinberg nuendo price uniblue registrybooster 2009 download cheap photoshop programs adobe photoshop elements cheapest buy windows 7 future shop adobe presenter 7 download microsoft office 2003 sale buy quarkxpress 8 for mac purchase adobe cs3 design premium purchase after effects cs3 paperport professional 12 prices cakewalk download parallels desktop price buy microsoft windows 7 home premium cheap adobe after effects for mac how to purchase windows 7 online download microsoft streets and trips 2008 microsoft office 2003 cheapest buy windows 7 online singapore purchase autodesk 3ds max 2009 buy windows xp pro best price adobe flash cs3 buy uniblue registrybooster 2009 cheap windows 7 ultimate retail buy autodesk autocad buy microsoft office document imaging purchase microsoft office 2003 buy windows xp media centre edition discount microsoft windows 7 ultimate windows 7 price upgrade cheap adobe photoshop software burnaware professional price buy acronis true image 2010 windows 7 price change buy acrobat 7 where to buy adobe flash cs3 quicken 2010 price buy windows xp corporate buy office 2007 student product key windows 7 price hong kong buy windows 7 64 buy acrobat professional 9 symantec winfax pro 10.4 buy cheap windows 7 keys adobe photoshop cs4 buy buy microsoft visio 2007 turbotax deluxe 2009 download windows xp price in rupees buy lightroom software buy windows 7 buy windows 7 serial key steinberg nuendo 3 download download autodesk 3ds max 9 buy ms project online windows 7 price egypt windows 2008 enterprise download parallels mac download adobe lightroom sale cheap cubase 5 where to buy windows xp service pack 2 purchase windows vista download cheap windows 7 in singapore lowest price microsoft office purchase windows 7 license key where can i buy windows 7 starter edition buy i.r.i.s. readiris pro 11 cheap windows xp operating system buy office 2003 key where to buy windows xp cheap autocad mechanical 2009 download buy matlab software buy 3ds max 2010 student download dragon naturally speaking autocad inventor download get autocad 2010 buy adobe illustrator cs2 buy windows 7 mac windows xp price canada steinberg cubase sx3 download cheap windows 2003 enterprise download adobe illustrator cs3 can i buy windows xp online windows xp price in malaysia buy adobe cs4 suite best price adobe illustrator cs3 download font folio 11 acdsee pro license key cs3 production premium mac ms streets and trips 2008 download download adobe illustrator mac windows 7 price in india where can i buy cubase sx3 windows vista download iso roxio creator 2010 coupon code microsoft office price student windows 7 home premium 64 bit oem buy microsoft frontpage software buy windows xp 64 pro cheap windows 7 home premium full version buy burnaware professional cheap microsoft works 9 microsoft visio download adobe cs4 web premium oem download disk director cheap adobe creative suite cs4 microsoft money home and business download buy parallels desktop 5 for mac cheapest norton 360 3.0 lightroom price buy windows vista pro microsoft money buy online buy microsoft expression blend 3 buy windows 7 full version for students purchase lightroom 2 buy microsoft office ultimate pdf converter professional 6 promotional code buy adobe cs3 design premium buy indesign cs3 software buy windows vista ultimate upgrade acdsee photo editor download microsoft office 2003 professional cheap windows 7 for college students illustrator cs3 download download adobe indesign cs4 cyberlink powerdirector prices buy windows vista ultimate license buy access 2003 online windows 7 price guide mathcad price buy after effects cs4 mac cheap fl studio 8 xxl cheap photoshop elements 8 buy windows vista home premium oem buy wordperfect x3 buy windows 7 home premium 64 bit buy windows 7 brisbane buy windows 7 bangkok autodesk mudbox price purchase vista license cheap adobe premiere elements 8 download adobe creative suite 4 design premium best price microsoft excel 2003 buy microsoft project 2000 microsoft expression price discount photoshop elements 8 cheap maya software 3ds max sale buy windows 7 ebay windows 7 price 2010 deskshare videoeditmagic 4.3 price buy windows xp 2010 norton 360 price comparison buy windows xp used adobe contribute mac purchase windows 7 for mac buy windows vista home premium product key buy windows 2003 datacenter buy windows 7 professional cheap microsoft windows 7 ultimate buy sony vegas pro 8 purchase access 2007 final cut express 4 cost download microsoft visio 2007 buy onenote 2003 photoshop lightroom for mac symantec pcanywhere download windows 7 price pakistan buy premiere pro cs3 cheap windows 7 for students in australia web page maker 3 download buy windows xp home sp3 adobe photoshop best buy cheap windows 2008 enterprise buy windows 7 direct download download microsoft mappoint 2009 buy windows xp home download microsoft autoroute 2007 europe ashampoo burning studio download buy windows xp calgary archicad 13 download adobe cs4 design premium trial price photoshop elements 8 windows 7 home premium cheapest autodesk lustre pricing purchase archicad 13 acdsee pro 2 download windows 7 discount canada vmware workstation 7 download discount autodesk 3ds max 2009 buy autodesk inventor professional buy windows xp home full version buy windows 7 language pack buy microsoft office 07 buy microsoft excel 2007 download propellerhead reason 4 mappoint 2009 european buy access 2007 only buy frontpage 2003 purchase windows 7 ultimate online purchase microsoft windows vista buy dragon naturally speaking 10 oil price vista gadget pinnacle studio 14 best price cheap corel video studio pro x2 buy photoshop 7 for mac buy adobe cs3 design premium mac download ashampoo burning studio 9 cheap microsoft project 2007 dvd ripper platinum 5 buy adobe premiere pro cs4 download best price microsoft windows vista windows 7 discount for high school students purchase windows 7 professional (64 bit) compare price photoshop buy windows 7 philippines buy microsoft office powerpoint 2007 purchase windows xp sp3 buy photoshop elements 8 mcafee total protection 2009 download best buy autocad 2009 buy windows vista singapore purchase windows 7 now buy windows xp mumbai buy windows 7 ultimate 64 bit oem windows 7 price kenya ms works download adobe acrobat 9 oem buy windows 7 downloadable adobe cs4 web premium trial cheap windows 7 professional best price windows 7 home premium oem download adobe photoshop elements 6 navisworks manage price windows 7 price comparison buy guitar pro 5.2 download acronis true image 11 buy nero 8 ultra edition acdsee price download adobe robohelp 8 buy powerdirector 7 ultra imsi turbofloorplan home and landscape pro 12 buy buy microsoft expression studio 2 windows 7 discount for military buy windows 7 30 download pinnacle studio 12 ultimate adobe acrobat price comparison mappoint 2009 europe buy cheap avanquest mylogomaker professional 2 buy windows xp cheap microsoft office discount code buy windows 7 switzerland buy windows xp volume license buy norton 360 download cheap adobe photoshop cs3 download microsoft expression studio 3 buy office 2010 professional fl studio 8 xxl download buy microsoft office 2007 home and student cheap adobe cs4 design premium abbyy finereader 9.0 express edition where to buy streets and trips 2010 office 2007 price student buy roxio creator 2010 cheap adobe cs4 master collection mac buy windows xp ebay cheap indesign software buy corel photoimpact x3 download avanquest mylogomaker professional 2 cheap ashampoo burning studio 8 adobe captivate pricing autocad architecture oem buy microsoft office pro 2007 where can i buy powerpoint 2003 turbo tax cost buy windows 7 india online purchase windows 7 license online buy adobe flash cs4 buy windows vista ultimate product key buy cs4 mac buy adobe indesign cs4 best buy microsoft windows 7 ultimate cheap adobe dreamweaver cs4 mac cheap windows 7 canada roxio creator 2009 special edition microsoft office 2010 price in india windows 7 price canadian buy windows xp embedded download corel draw 12 adobe creative suite 4 production premium download buy adobe photoshop cs3 extended buy windows vista business 64 bit buy ms office 2003 pro best buy quicken 2010 buy microsoft office for mac cheap buy adobe after effects cs4 cheap norton 360 3.0 best price adobe cs4 master collection windows 7 price for teachers buy windows xp student purchase adobe acrobat 8 professional buy sql server guitar pro 5 mac download
Home » ShapeSheet

Choose Colors with Shape Data Fields

Submitted by Visio Guy on October 21, 2009 – 6:54 am | | 2984 views 10 Comments

choose-colors-in-shape-data

Do you have shapes that contain multiple colors that you’d like to easily change?

Wouldn’t it be neat to be able to specify those colors in Shape Data fields, along with other parameters for the shape?

Visio’s Shape Data fields don’t directly support colors, but I’ve come up with a workaround. You can read how I did it, or just get the download and re-use what I’ve already built!

If Only I Could Pick Colors in Shape Data Fields!

I wanted to allow users to pick colors for various parts of shapes at the same time that they specify other values: namely when they are editing Shape Data fields.

Previously, I had bastardized the foreground and background colors, and even shadow colors to allow users to benefit from built-in color picking interfaces. See Sankey Diagram Shapes for Visio, and Automatic Chevron Process Shape for examples of this. It works, but it isn’t immediately obvious to the user.

Other times, you have to expect user to sub-select sub-shapes, then format them individually. This can be annoying, because they might not know how to sub-select. Also, if your shape has data fields anyway, why not set all variables in one place?

Color-picking in the Shape Data window seems a natural thing to do. After all, Visio allows you to define fancy data types like dates:

define-date-field

This gives you a nice, rich “picker” control like this calendar:

choose-date

So why not allow color to be one of the available Shape Data types?

Heck, even ConceptDraw allows you to define color as a Custom Property data type:

concept-draw-color-field

Sure, this drop-down isn’t as elegant as a color picker might be, but this gets the job done! (And Yes, I’m trying to provoke the Visio team in Redmond, if you haven’t noticed.)

Workaround: Choose Colors by Name

Since Visio is so customizable, you find yourself pushing it all the time. And when you push enough, you end up against a wall, such as this one, with “no color picker shape data type” spray painted all over it. But that same customizability allows you to come up with workarounds, time and time again.

This time, the next best thing was to create a drop-down list of named colors.

color-names-drop-down

While visual pickers are nice, text drop-downs offer the consolation that you can quickly navigate them by typing the first letter of the color you are searching for. And today’s example has 140 different colors, so that quick navigation is nice to have.

So now you just need to learn and memorize what colors like: “Dark Goldenrod”, “Lavender Blush” and  “Powder Blue” actually mean!

Building Color Lists in the ShapeSheet

To make this work, we need two lists: Names and RGB formulas. In the ShapeSheet, you can specify a color with a formula like this:

FillForegnd= RGB(139, 69, 19)

Which yields a reddish-brown color.

We can then make a list of RGB formulas, and a corresponding list of names for those colors. The LOOKUP and INDEX ShapeSheet functions can then be used to transform a name into a color-formula.

Inside of the shapes I built, the ShapeSheet has some user cells:

User.colorNames = “AliceBlue;AntiqueWhite;Aqua;…”
User.colorValues
= “RGB(240,248,255);RGB(250,235,215);RGB(0,255,255);…”
User.color1
= INDEX( LOOKUP( Prop.color1, User.colorNames ), User.colorValues )

The first two cells are self-explanatory. User.colors, however, is a bit more complicated.

You’ll notice that it references a Shape Data field called Prop.color1.This contains the value that is selected by the user in the Shape Data window. Once we have a name, we find it’s position in the name list using LOOKUP. Then we grab the RGB formula from the other list using that position as an argument to INDEX.

Prop.color1’s important cells look like this:

Prop.Color.Type = 1 …fixed list
Prop.Color.Format
= User.colorNames
Prop.Color.Value
= INDEX( 139, Prop.color1.Format )

Note that Prop.Color.Format could just have easily contained the full list of names. But I put it in User.colorNames, so that it would be available for multiple fields. More on that later.

How to Get a Big List of Colors

I actually came to the idea of using color lists while working on another project, in which I was coding in C#. When you use the .NET framework, you can choose colors from built-in set, defined in the System.Drawing namespace.

I wrote a small procedure to extract all of those built-in colors, and build two lists at the same time: one for the color names, and one for the RGB ShapeSheet formulas. Programmers might be interested in this snippet, non-coders can skip right over it:

private void _dumpBuiltInColorInfo()
{
 // Collection to store the names of the colors,
 // and the RGB values:
 List colorNames = new List();
 List colorValues = new List();

 // Use reflection to analyze the System.Drawing.Color
 PropertyInfo[] piItems = typeof(System.Drawing.Color).GetProperties();

 // Loop through the items in the properties collection:
 foreach (PropertyInfo pItem in piItems)
 {
 Type t = pItem.PropertyType;

 if (t == typeof(System.Drawing.Color))
 {
 // Get the color object:
 Color c = (Color)pItem.GetValue(null, null);

 // Add the name to the names:
 colorNames.Add(c.Name);

 // Add a Visio-compatible color formula to the values:
 string rgbFormula = "RGB(" + c.R + "," + c.G + "," + c.B + ")";
 colorValues.Add(rgbFormula);
 }
 }

 // Dump a semi-colon-separated list of color names:
 Console.WriteLine(string.Join(";", colorNames.ToArray()));

 // Dump a semi-colon-separated list of RGB formulas:
 Console.WriteLine(string.Join(";", colorValues.ToArray()));

 // Copy the Output for use in a Visio shape's ShapeSheet!
}

Specifying Lots of Colors Using Shape Data Fields

To test it out, I built a shape that allows you to pick four different colors via Shape Data fields. It looks like this:

four-colors-on-a-shape

This shape has the cells User.colorNames and User.colorValues that we discussed before. But in order to simplify things a bit, I added another cell that defines a custom ShapeSheet function:

User.colorFunction = INDEX( LOOKUP( ARG(“chosenColorName”), User.colorNames), User.colorValues )

This allows me to define the logic for looking-up and indexing color names and color values  in one central place. I can then re-use it multiple times without proliferating copies of that logic. If you’ve read User-defined ShapeSheet Functions in Visio 2007, then you’ll understand. If not, go have a look!

To get four different color values, I invoke the custom function like this:

User.color1 = EVALCELL( User.colorFunction, “chosenColorName”, Prop.color1 )
User.color2 = EVALCELL( User.colorFunction, “chosenColorName”, Prop.color2 )
User.color3 = EVALCELL( User.colorFunction, “chosenColorName”, Prop.color3 )
User.color4 = EVALCELL( User.colorFunction, “chosenColorName”, Prop.color4 )

There are four corresponding Shape Data cells that expose the data to the user: Prop.color1, Prop.color2, Prop.color3 and Prop.color4. You can see that by using EVALCELL to call the custom function, I only have to change one argument.

If I ever modify my color-lookup-logic, I will only have to change one formula: User.colorFunction. Pretty neat, and only available in Visio 2007 or later, by the way.

Accessing the Custom Colors from Sub-shapes

If you set up these User-cells and Prop-cells in a group, then it is easy to have sub-shapes reference the values.

Suppose your group has an ID of 5. This means your group can be referenced by the name “Sheet.5″.

Sub-shapes in the group can then refer to Sheet.5!User.color1, Sheet.5!User.color2 and so on. To control the color of a sub-shape, then, you might set this formula:

FillForegnd = Sheet.5!User.color1

or even better, if you want the sub-shape to ONLY be color-able via Shape Data:

FillForegnd = GUARD(Sheet.5!User.color1)

The download contains a single shape and a group shape, both armed with big, long drop-down lists of colors, ready for you to use in your own projects, or pick apart and learn from. Have fun!

Previously, I had bastardized the foreground and background colors, and even shadow colors to allow users to benefit from built-in color picking interfaces. See Sankey Diagram Shapes for Visio, and Automatic Chevron Process Shape for examples of this. It works, but it isn’t immediately obvious to the user.

Related Posts

  1. Month Math
  2. How Many Fill Colors Can You Put on a Visio Shape?
  3. Visio Microphone Shape
  4. A Re-programmable Visio Multi-shape: The Configurable Stickman!
  5. Center-sizing Smart Shapes

10 Comments »

  • Wapperdude says:

    Kudos Chris!

    That would save so much time, and provides so much more flexibility! Of the various shapes that I’ve provided a color selection option — what a pain to have to code those into the shape sheet manually.

    Thanks!
    Wapperdude

  • Visio Guy says:

    Thanks WD,

    I am thinking of creating some sort of tool or Excel spreadsheet that allows you to easily select sub-sets of those 140 colors so you can easily build the necessary ShapeSheet functions with shorter lists.

    After all, how many people need ‘Rosy Brown’ or ‘Thistle’, let alone know what they look like?

    - Chris

  • Jumpy says:

    Hi Chris,
    using Shape Sheet functions for this, is a great idea. I used a method with Color choosing in the Shape-Data window, too, but used the Dependson-Function to change LineColors via SETF, whenever an new color was selected in the Shape-Data-Window.
    The Index/Lookup-combination is clever,too. I used many If-Functions. That was OK, when you can only choose between 4 colors, but for 140 colors that would have been akward.
    Therefore I’ll use your method in the future.

    But what impressed me most, was a small thing: The Color-Symbol in the Kontextmenu of the shape. How did you know the nessesary ButtonFace number? Is there a list with pictures and IDs on the internet somewhere? Or is there an easy way to find Visios Icons and their number?

    Thanks,
    Jumpy

  • Visio Guy says:

    Servus Jumpy!

    The ButtonFace IDs is something I have wanted to write about for a while, but there are a few things that I still wanted to research.

    You can set up a shape that will let you rapidly explore buttons faces. Smart Tags can show the buttons all the time, so you don’t always have to right-click the shape. Try this:

    1. Insert a Smart Tag row
    2. Set DisplayMode = 2 (always display)
    3. Set ButtonFace = 0
    4. Insert > Field and set a Custom Formula = SmartTags.Row_1.ButtonFace to display the current button face in the shape’s text
    5. Set EventDrop = =SETF(GetRef(SmartTags.Row_1.ButtonFace),SmartTags.Row_1.ButtonFace+1)
    6. Use Ctrl + Drag to copy a shape, then hit F4 to repeat the copy the shape over and over and over

    You’ll now have an array of shapes with incremented ButtonFace ids, and you should be able to easily see which icon corresponds to which number.

  • Jumpy says:

    Hi Chris,
    using Smart Tags is a good idea. I pushed it a little further:

    Used Step 1-4 from above to create a shape.
    I created a new stencil and called it ButtonFace.
    Then I put the Shape in the new stencil as a new master and called it BF.
    Then I wrote this little VBA-Sub which constructs a small table with ButtonFaceIds from 0 to 1000.

    Sub Add_BF_Shape()

    Dim i, j, As Integer
    Dim Shp As Shape

    For j = 0 To 19
    For i = 1 To 50

    Set Shp = Application.ActiveWindow.Page.Drop(Application.Documents.Item(“ButtonFace.vss”).Masters.ItemU(“BF”), 1, 1)

    Shp.Cells(“SmartTags.Row_1.ButtonFace”).Formula = 0 + j * 50 + i
    Shp.Cells(“PinX”).Result(70) = (15 + 20 * j)
    Shp.Cells(“PinY”).Result(70) = (290 – 5 * (i – 1))

    ActiveWindow.DeselectAll

    Next i
    Next j

    End Sub

    When you change the 0 in the first row with Shp.Cells… you can define another start number. So if you exchange 0 with 1000 the Sub will produce a list with ButtonFaceIDs from 1001-2000.

  • [...] (17.6 downloads/month, 0.9 months) Choose Colors with Shape Data Fields [...]

  • eLiz says:

    Hey Chris,

    I just want to create a new shape with the function you described here. I remembered your article and tried it out. At the moment I use the Visio 2010 beta and the result was: Black. All the time the shape was colored black.
    Hm, with Visio 2003 I thought it should be better. But: Black…

    Now I downloaded your file and what happens: black

    When I refer to the cell User.Color Visio always puts a “0″ as value?!?!
    Do you know what the problem can be?

    Regards,
    Lisa

  • Visio Guy says:

    Hi eLiz, there seems to be a problem with German systems, and I haven’t had the time to play with Visio-DE.

  • eLiz says:

    Hey Chris,

    oh no… I thought to have found a simple and elegant solution for this pattern. I use it really often but at the moment I need the workaround with thousands of “If”…

    But thanks for your response,
    Regards, eLiz

  • Visio Guy says:

    Hi eLiz,

    There may be a simple fix for this, I just don’t have time in the next few weeks to research auf einem deutschen Rechner.

    I think there is probably a good work-around for this, so don’t give up yet! :)

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.