Site icon bVisual

Automatic Line and Segment Lengths in Visio

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

NameValuePrompt
ShowUnitsTRUE“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

NameLabelPromptTypeFormatValueInvisible
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

ActionMenu
SETF(GetRef(User.ShowUnits),NOT(User.ShowUnits))IF(User.ShowUnits=1,”Hide &Units”,”Show &Units”)

That is all that is required!

Synchronizing Visio Shape Fill Color (or almost any cell) across pages

I was recently asked how the color of one shape can be changed and for other shapes to be automatically updated to the same color … even if they are on different pages! Well, it is possible with Microsoft Visio’s awesome ShapeSheet formulas. In fact, this capability is not limited to the FillForegnd cell ……

Positioning Visio Shape Text Block with a Control Handle

I was recently asked how a control handle can be added to a Visio shape so that it can be used to re-position the text block. Fortunately, it is extremely easy to setup, and requires just two formulas to be updated in the ShapeSheet. This is a great use of the SETATREF(…) function. (more…)

Understanding Segments of Visio Geometry

I recently had to revise my understanding of the POINTALONGPATH(…) function in Visio because I was getting a #REF! error in some cases. My particular scenario requires a line with a number of vertices that are initially all in a straight line but can be moved by dragging controls around that each vertex is bound…

Custom Color Themes in Visio?

I was recently looking into custom color themes for corporate branding in desktop Microsoft Visio and became re-aware how different Visio still is from the rest of the Microsoft Office applications. A Visio page or document does not need to have any theme applied, but the documents of the other Office applications always have a…

When is a Visio Callout not a Callout?

I have been a Visio user/developer since the mid-1990’s and seen the word “callout” used as part of the name of many master shapes in Visio. The images below show five ways that the term “callout” has been applied to the name of Visio master shapes. Generally, each evolution has been an advance on the…

Using Visio Color by Value on Connectors

Data Graphics in Visio Plan 2 and Visio Professional is great, but it only enables us to use them with 2D shapes in Visio, i.e. not on connectors. So, what if you want to change the line colour of the connectors between the 2D shapes because of the data flowing between them? Well, it is…

Exit mobile version