• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

bVisual

  • Home
  • Services
    • How Visio smartness can help your business
    • Visio visual in Power BI
    • Visio Consulting Services
    • Visio Bureau Services
    • Visio Training and Support Services
  • Products
    • Visio Shape Report Converter
    • SS Plus
    • LayerManager
    • visViewer
    • Metro Icons
    • Rules Tools for Visio
    • The Visio 2010 Sessions App
    • Multi-Language Text for Visio
    • Document Imager for Visio
    • multiSelect for Visio
    • pdSelect for Visio
  • Case Studies
    • Case studies overview
    • Using Visio in Education for GIS
    • Visualizing Construction Project Schedules
    • Visio Online Business Process Mapping
    • Nexans Visio Template
    • CNEE Projects, WorldCom
    • Chase Manhattan Bank
  • News
    • Recent news
    • News archive
  • Resources
    • Articles➡
      • ShapeSheet Functions A-Z
      • Comparing Visio for the Web and Desktop
      • Customising Visio Shapes for the Web App
      • Key differences between the Visio desktop and web apps
      • Using the Visio Data Visualizer in Excel
      • Using Visio in Teams
      • Creating Visio Tabs and Apps for Teams with SharePoint Framework (SPFx)
      • Designing Power Automate Flows with Microsoft Visio
      • Innovative uses of Visio Lists
    • Webcasts ➡
      • Visio in Organizations
      • My session and other Visio sessions at MSIgnite 2019
      • Power up your Visio diagrams
      • Vision up your Visio diagrams
      • The Visio 2010 MVP Sessions
    • Visio Web Learning Resources
    • Books➡
      • Visualize Complex Processes with Microsoft Visio
      • Mastering Data Visualization with Microsoft Visio
      • Microsoft Visio Business Process Diagramming and Validation
      • Visualizing Information with Microsoft Visio
  • Blog
    • Browse blog articles
    • Visio Power BI articles
    • Visio for Web articles
    • A history of messaging and encryption
  • About us
    • About bVisual
    • Testimonials
    • Bio of David Parker
    • Contact Us
    • Website Privacy Policy
    • Website terms and conditions
    • Ariba Network
You are here: Home / Shape Design / ShapeSheet Formulas / Automatic Line and Segment Lengths in Visio

Published on July 16, 2021 by David Parker

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!

Fixing dimensions of 2D shapes

I am often asked what makes Visio unique and makes it stand out from the crowd, especially in today’s online world. Well, I think there are many reasons, but one of them is the ability to create scaled drawings with parametric components of specific dimensions. This was crucial for my adoption of Visio back in…

Smart Radio Buttons and Check Boxes in Visio

A recent project requires an interactive tutorial within Microsoft Visio desktop where a lot of the questions need a single answer using radio buttons, or multiple-choice answers using check boxes. I thought that this would be a great use of the list containers capability because the questions and answers could be part of the container…

Using Button Face Ids in Visio

Microsoft Visio desktop has the ability to display icons from a built-in list of Office icons on Actions and Action Tags (nee Smart Tags). These can be set in the ShapeSheet by using the desired number from several thousand in the ButtonFace cell. Although there is the ability to add better icons using code, the…

Grid Snapping Revisited

I have previously tackled the subject of snapping to grids in Visio desktop (see https://bvisual.net/2018/06/19/really-snapping-to-grids-in-visio/ ) but a recent project required me to improve the example because it did not respond to all cursor arrow keys. The problem was that the previous solution could not understand which arrow key had been clicked, therefore it did…

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…)

Related

Filed Under: Shape Data, Shape Reports, ShapeSheet Formulas Tagged With: ShapeSheet, Visio

About David Parker

David Parker has 25 years' experience of providing data visualization solutions to companies around the globe. He is a Microsoft MVP and Visio expert.

Reader Interactions

Comments

  1. Evert van der Helm says

    February 12, 2024 at 3:31 pm

    Thanks for this example to make PATHLENGTH() work for my High Voltage line project!

    A minor remark: PATHLENGTH() is not recalculated when you change the rounding of a line (e.g. the bending radius for a cable).
    Work-around: change/add/delete a segment (or move a point of the path)

    A question:
    Can you specify in text how the contents of cell Controls.TextPosition.XBehavior looks like? The figures nor the tables show that information. I tried to figure it out, but my experience with controls is too limited, I am afraid…

    Log in to Reply
  2. Evert van der Helm says

    February 12, 2024 at 4:06 pm

    Ah… I was using my own master (a HV cable), but should have used the Dynamic Connector master that was used in the example above.

    In the Control section of my shape, I changed next cell:
    Controls.TextPosition.Xbehavior=IF(OR(STRSAME(SHAPETEXT(TheText),””),HideText),5,0)

    In the TextTransform section, I changed next cells:
    TxtPinX=SETATREF(Controls.TextPosition)
    TxtPinY=SETATREF(Controls.TextPosition.Y)

    This works perfect for my master!
    Thanks again for sharing your knowledge, David!

    Regards – Evert

    Log in to Reply
  3. Evert van der Helm says

    February 13, 2024 at 4:15 pm

    Ah… I was using my own master (a HV cable), but should have used the Dynamic Connector master that was used in the example above! That master comes with formulas that must be set when starting from scratch.

    The answer to my question of February 12 is as follows:

    1) Insert Prop.TotalLength as a Text Field

    2) In the Control section, change next cells:
    Controls.TextPosition.Xbehavior=IF(OR(STRSAME(SHAPETEXT(TheText),””),HideText),5,0)

    3) In the TextTransform section, change next cells:
    TxtPinX=SETATREF(Controls.TextPosition)
    TxtPinY=SETATREF(Controls.TextPosition.Y)

    Regards – Evert

    Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

  • LinkedIn
  • Twitter

Recent Posts

  • Co-authoring and Commenting with Visio Documents
  • Fixing dimensions of 2D shapes
  • Merging Linked Data from Similar Tables
  • Smart Radio Buttons and Check Boxes in Visio
  • Using Button Face Ids in Visio

Categories

Tags

Accessibility Add-Ins Connectors Containers Data Export Data Graphics Data Import Data Visualizer Educational Excel GraphDatabase Hyperlinks Icon Sets JavaScript LayerManager Layers Legend Link Data to Shapes Lists MSIgnite MVP Office365 Org Chart PowerApps PowerBI PowerQuery Processes Setup and Deployment Shape Data Shape Design ShapeSheet ShapeSheet Functions SharePoint 2013 SQL Teams Validation VBA Video Visio Visio 2007 Visio for the Web Visio Online Visio Services Visio Viewer Webinar

Footer

bVisual Profile

The UK-based independent Visio consultancy with a worldwide reach. We have over 25 years experience of providing data visualization solutions to companies around the globe.

Learn more about bVisual

  • Amazon
  • E-mail
  • Facebook
  • LinkedIn
  • Twitter
  • YouTube

Search this website

Recent posts

  • Co-authoring and Commenting with Visio Documents
  • Fixing dimensions of 2D shapes
  • Merging Linked Data from Similar Tables
  • Smart Radio Buttons and Check Boxes in Visio
  • Using Button Face Ids in Visio

Copyright © 2025 · Executive Pro on Genesis Framework · WordPress · Log in