The new containers feature in Visio 2010 is fantastic. If you have not heard of this feature then check out the product team blog article about containers here.
What I want to point out to all you shape developers how you can use some simple new ShapeSheet formulas to allow shapes to base calculations on the container they are associated with.
Take for example…
As you can see, I have setup a container that has a Base Value property containing the value 10. I also have a standard rectangle that contains a local value. Each rectangle also has a formula that simply multiplies the local value with the container’s base value when then are associated.
The formula is simple and can be contained within a single User cell.
IF(ISERR(CONTAINERSHEETREF(1)!Prop.BASEVALUE*Prop.Value),"?",CONTAINERSHEETREF(1)!Prop.BASEVALUE*Prop.Value)
CONTAINERSHEETREF() is key. This new ShapeSheet function returns the reference to the container. Notice that we also need to test that against any errors if the shape is not contained within a container. It also handles a situation where the containing container does not have the Prop.BASEVALUE property defined
For your convenience I have attached a sample diagram that I used for this example.