Many years ago, I wrote some VBA code to calculate the length of a multi-segment line in Visio, see Automating Area and Perimeter Length Shape Data , but Microsoft have since provided a handy ShapeSheet function, PATHLENGTH(…), to do the same without any VBA. The function is described on one of the pages in Visio ShapeSheet Functions O-R , but here is one way that it can be incorporated into a useful shape for, say, cabling or piping, and thus be available in Shape Reports. Moreover, the Shape Data can display the length of each of the segments in the line, in addition to the total length.
I chose to modify the Dynamic Connector master in this example, but it could be added to any 1D master shape.
I also chose to add in the ability to select the display units and the number of decimal places. The following images are of the ShapeSheet in both Value and Formula display modes.
|ShowUnits||TRUE||“TRUE to Show Units, FALSE to Hide Units “|
|“The Format String for the length display”|
The REPT(…) function will simply repeat the “0” character as many times as defined by the value of Prop.DecimalPlaces
|Length||“Length”||“The built-in units are inches”||2||“”||GUARD(|
|TotalLength||“Total Length”||“The length in the selected units”||0||“”||GUARD(|
|DisplayUnits||“Display Units”||“Select a unit for the display”||1||“in;ft;yd;mm;cm;m”||INDEX(3,Prop.DisplayUnits.Format)||FALSE|
|DecimalPlaces||“Decimal Places”||“Select the number of decimal places”||1||“0;1;2;3;4;5;6;7;8;9”||INDEX(1,Prop.DecimalPlaces.Format)||FALSE|
|Segmentn||“Segment n Length”||“The length of segment n with the selected unit and decimal places”||0||“”||GUARD(|
Where n is from 1 to as many as you expect to be the maximum number of segments.
The Length Shape Data row could be Invisible=TRUE.
The invisibility or each of the multiple Segmentn rows is controlled by checking if there is an error returned by the PATHLENGTH(…) function.
|SETF(GetRef(User.ShowUnits),NOT(User.ShowUnits))||IF(User.ShowUnits=1,”Hide &Units”,”Show &Units”)|
That is all that is required!
There are literally thousands of master shapes in the stencils supplied with Microsoft Visio, so I guess that mistakes can creep in. One error that I have noticed is the inability of the default text control handle of many of the network shapes to actually move the text block horizontally. (more…)
I have only been developing Visio solutions for 25 years, but I got a surprise this week when I was trying to understand why I couldn’t update the value of a Shape Data row of multiple selected shapes. It is something that I often do, so it took me a while to understand why I…
There are times, in Visio, when you just need to ensure that the text in a primary shape is synchronised with the text in different secondary shapes … even if they are on different pages of a Visio document. My previous article, Forcing Display Update of Inherited Data Values , describes a method of synchronising…
I was going to title this “When is a truth not a truth?” because I have found that Visio can sometimes refuse to apparently update the displayed value in a cell, even though it has been changed. However, this was, in this instance, down to a misunderstanding of the formula evaluation events on my part.…
A reader asked how to fill a shape with a custom fill pattern from a fixed list in of a shape. They had no trouble with the first 25 standard fill patterns, but couldn’t figure out how to apply a custom pattern. So, I shall try to explain how this can be done … (more…)
Now that a version of Visio is being rolled out as part of the commercial subscription of Microsoft 365, what is the difference between it and the Visio Web App that is delivered by Visio Plan 1 and Visio Plan 2 subscriptions? Moreover, can a Visio diagram created by an M365 user be round-tripped with…