Sometimes, when designing a shape in Visio, you want to allow a user to make changes to your shape such as color, size or position, but also have some mechanism for returning the shape to a default state. In this post I’m going a explore a method that works with Visio’s master inheritance functionality.
Inheritance
As you know, when you drag a master onto the page, most of the resulting instance shape’s cells will inherit their formulae and values from that master. You can see that reflected in the ShapeSheet where black cell text represents an inherited formula or value and blue text a local (to the shape instance) version. For most shapes Visio will write a local value into the PinX and PinY cells as the shape is dropped:
Other cells will only become local when a change occurs in the instance, such as when the user applies a fill color to the shape.
In general, the benefits of inheritance are improved performance, reduced memory usage and a smaller file size (something that Visio 2013 does an even better job of).
A standard approach
Let’s look at an example of a fairly standard approach to resetting a shape’s fill color. Here you could add an Actions row and use a SETF function to fire the default formula or value into your target cell (FillForegnd in this case):
The only problem here is that we’ve still ended up with a non-inherited cell value – i.e. it’s local.
Have a look at the steps:
- as the shape was first dropped FillForegnd inherited its formula and value from the same cell in the master.
- when the user then applied their own fill color, via the UI, the cell value became local.
- hitting our reset, as above, only resets the FillForegnd value to be the same as the value in the master but not directly inherited.
Resetting inheritance
The alternative is, rather than use the SETF function to set the local formula, use SETF to reset the cell’s inheritance by firing in an “=” instead.
Setting a cell’s formula to “=”, whether entering it manually in the ShapeSheet, using SETF or via code tells Visio to re-inherit the cell formula.
So you can now lose the User.DefaultColor cell and just keep your default color value in the master’s FillForegnd cell:
You can, of course, apply this to any other cells you like. In the accompanying sample Visio document and image below is an example that allows the user to set custom fill colors on each of the satellite sub-shapes and change their relative positions – all backed by master inheritance, to reset to default values.