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.
User-defined Cells
Name | Value | Prompt |
ShowUnits | TRUE | “TRUE to Show Units, FALSE to Hide Units “ |
FormatString | “0.”& REPT(“0”,Prop.DecimalPlaces)& IF(User.ShowUnits=1,” u”,””) | “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
Shape Data
Name | Label | Prompt | Type | Format | Value | Invisible |
Length | “Length” | “The built-in units are inches” | 2 | “” | GUARD( PATHLENGTH(Geometry1.Path) ) | FALSE |
TotalLength | “Total Length” | “The length in the selected units” | 0 | “” | GUARD( FORMATEX( Prop.Length, User.FormatString, “in”, Prop.DisplayUnits) ) | FALSE |
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( FORMATEX( IF( ISERR(PATHLENGTH(Geometry1.Path,n)), 0, PATHLENGTH(Geometry1.Path,n) ), User.FormatString, “in”, Prop.DisplayUnits) ) | ISERR(PATHLENGTH(Geometry1.Path,n)) |
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.
Actions
Action | Menu |
SETF(GetRef(User.ShowUnits),NOT(User.ShowUnits)) | IF(User.ShowUnits=1,”Hide &Units”,”Show &Units”) |
That is all that is required!
Pushing Data Visualizer in Visio beyond its limits
My last post was about some of the lessons learnt when trying to push Data Visualizer to its limits, but this one has some ways of overcoming these limitations. The main lesson learnt is that DV binds the shapes within the DV container shape, CFF Data Visualizer, and controls some of the ShapeSheet cells that…
Pushing Data Visualizer in Visio to the limits!
Regular readers of my blog will know that I like to use the Data Visualizer (DV) in Visio Plan 2, but I recently tried to help a user who really decided to push it to the limits. In this scenario, there were multiple connections, but with different labels, being created between the same flowchart shapes,…
Setting Theme defaults in Visio
I was recently asked how to change the default font size and line weight in Visio, and then saw then many others are asking the same sort of question. I found one reasonable answer suggesting that you should create a new document from your required template, then edit the Styles to suit, and then save…
Taking Visio Actions Rows to the limit
I recently (re-)discovered that there is a limit to the number of Actions section rows that will be evaluated for display on the right mouse menu of a Visio shape. I have not hit a limit (yet) for the number of rows that can be added to the Actions section … so why is there…
A Multi-Time Zone Clock for Visio
I wrote a post about making a clock face in Visio fifteen years ago, but a reader recently asked about displaying multiple time zones. Well, I have previously written about time zones in Visio, so I accepted the challenge to improve upon my earlier work. (more…)
Update any Visio ShapeSheet cell with External Data
When Microsoft introduced a new way of linking external data to Visio shapes in 2007, I initially bemoaned the inability to update anything but Shape Data row values, unlike the old database add-on that I had been using for 10 years. The new method, though, has many advantages over the old way, not least that…
Leave a Reply