Shapes that calculate based on their container
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 https://blogs.msdn.com/b/visio/archive/2009/08/25/organizing-diagrams-with-containers.aspx
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.
Container Child Calculation Sample.vsd
Comments
- Anonymous
July 05, 2011
To see an extended version of this concept, take a look at this article: http://bit.ly/m2AZW4. It involves a list embedded in a container, which is, in turn, embedded in another list. The shapes in the innermost list calculate values based on data in all of the parent objects.