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!
Using Notepad++ to Edit Visio ShapeSheet formulas
Visio shapes get their smartness from the formulas that are entered into the ShapeSheet, but editing these formulas can be extremely tricky and prone to error because of the lack of a modern programmer’s interface. Formulas can be quite long (up to 64k characters) but even medium size ones like the one in User.GetWorkdays cell…
Adding a second Function header bar to Visio swimlanes
I was recently asked if a second function header bar can be added to the swimlanes in the cross-functional flowchart templates in Visio. Some swimlanes can get quite wide, so it can be useful to have a duplicate function header shape on the far-side too. It is quite simple to duplicate the existing function header…
More Parsing XML Data in Visio Shapes
My last article looked at parsing an XML string with a known structure and order of elements and attributes. This can be acceptable in some scenarios, but what if the elements or attributes are in a different order? Then it is necessary to use the element and attribute names rather than their index position. This…
Parsing XML data in Visio Shapes
One of my current projects uses XML data, and some of the values in the XML data control the display and content of Visio shapes. Therefore, I looked deeper into how the XML data can be used directly to control parts of the graphics. Although the external data linking feature in Visio Professional and Visio…
Highlighting dirty text in Visio shapes
I suppose I should explain what I mean by dirty text first 🙂 I often display the value of a Shape Data row in Visio text, but sometimes the solution requires that the value is also editable. This is ok if the client accepts that all editing is done with the Shape Data window or…
My new book on Visualizing Processes with Microsoft Visio has launched
Back in the early 1990s, there was an application called ABC Flowcharter that was the market leader for diagramming business flowcharts, but some of the brains behind Aldus PageMaker saw an opportunity to create something smarter, and left to write the Visio product, with the stated aim to overtake ABC Flowcharter within 2 years. They…
Leave a Reply