• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Visio Guy

Smart graphics for visual people




  • Home
  • Hire Me
    • Hire Me
    • Résumé
  • Products
    • Products
    • Bubble Revision Shape
    • Layers to Pages Utility
    • Rack Unit Dimension Line
    • Radial Elements Tool with up to 100 Wedges
    • Text on a Circle Visio SmartShape
  • Index
    • Articles by Date
    • YouTube – VisioGuy
    • Download Information
    • Suggestion Box
    • Shop
    • Visio Art
    • Visio Links
    • – Visio Shapes & Stencils
    • – Visio Templates & Drawings
  • About
    • About
    • Donate
    • GitHub
    • jsFiddle
    • Reading List
    • Subscribe & Follow
      • – E-mail
      • – facebook
      • – Twitter
      • – RSS
    • Privacy Policy
  • Discussion Forum
You are here: Home / Development / Code / Path Analysis in Visio

Path Analysis in Visio

April 8, 2009 By Visio Guy 11 Comments

path-analysisIf you’re trying to take Visio to the next level by writing code for custom solutions, then you’ve likely run into some aspect of connections.

The well-commented VBA code (provided by guest-poster Al Edlund) which accompanies this article will help you make programmatic sense of the elemental stuff of connected Visio diagrams: connectors, connection points, OneD shapes, Connect and FromConnect.

You’ll also see how to produce connected diagrams, find out which shape is connected to which, and more importantly, do some path analysis to find the deeper meaning behind it all!

This guest post was developed and written by Al Edlund. Al is a fellow Microsoft Visio Most Valuable Professional (MVP), and is a networking expert, and a big fan of Visio. He’s also told me that networking is also his hobby, so when he’s working he’s playing, and when he’s playing he’s working!

Thanks Al for a great effort, now take it away!

Connectors, Connections and Paths

I have seen a couple of recent requests that have focused on how to understand what is connected in a Visio drawing. What is sometimes missed is that there is a difference between connected and a path, which is a series of connections. This path deconstruction is sometimes referred to as graph analysis and is the study of how nodes (vertexes) attach to each other via “edges”.

What is sometimes overlooked by the user who wants to analyze the drawing via automation is that there are two levels of domain specific knowledge that are needed. The first is what is being represented by the shapes on the page and the second is how the underlying add-in portrayed that information.

This led me to a put together a two-part project which you can read about in these pages, and download when you’re done with the words. The project focuses on these two items:

  1. Demonstrates some concepts in analyzing a drawing’s connections
  2. Analyzes the path information

Using the Path Analysis Application

Once you’ve OK’d the VBA macros in the Visio file and clicked the StartTest button on page one, you’ll be presented with the project’s main form:

path-analysis-dialog

Figure 1 Example Menu layout

The path analysis form has two groups. The left one is for demonstrating path analysis and the right one is for drawing (connection) analysis.

The path analysis has three sections: the analysis algorithm, the view layers, and the open Excel button. The analysis algorithms create topology pages to demonstrate search techniques. The edge information and path search information are drawn on different layers which can be turned on/off by the layer buttons. The Open Excel feature is included to allow the user to pull in external data. The description of the workbook/worksheets is included in the code module: modDrawData.

The ConnectionsSearch section has four buttons. Flowchart draws the modified Visio 2007 SDK navigation example. The Drawing button uses the included page connection search to capture the active page connections. The Network button discovers the data from the network page, and the PFD button discovers the data from the pipes/flow/diagram. Lastly, the Save2Excel8 button takes the data from the last analysis and exports it to an Excel2003 format.

Flowchart

The Visio SDK has an example of analyzing a drawing (DemoNavigatingDrawing) which combines both of these concepts (connection analysis and path analysis).

I’ve included a modified version of this flowchart analysis in the drawing.

flowchart-example

Figure 2 Flowchart Example used

The modifications include:

  • Adding an additional data entry function
  • Including a control transfer shape.

I added these to demonstrate that:

  1. In a drawing that is aware of the ‘directionality’ of dynamic connectors the developer may have to adopt a strategy that verifies that all shapes have been included
  2. Shape.Type = OneD shapes which are not ‘Dynamic connectors’ may be in the information path.

Network

I’ve included a network detail drawing as well which brings out a couple of other exposures. In this case the points that require attention include (once again) that OneD shapes may not necessarily be part of an information flow and (to make it a little more interesting) we have to track connector end-points based on their component and connection point.

Finally in the network connections the paths are assumed to be capable of ‘full duplex’ communications which removes the directionality aspect.

network-detail

Figure 3 Network Detail Drawing used

Piping Flow (PFD)

The example of a piping flow drawing (provided by another user) as starting points has three sets of objects we want to track. These are equipment (vertices), piping (edges), and instrumentation (probes). The interesting point here is that a probe attaches to a OneD shape (pipes) in the example drawing.

piping-flow

Figure 4 Piping-Flow diagram used

Both the network detail and PFD drawings also demonstrate that you have to be aware of the underlying add-in that created the drawing. In the case of the PFD drawing shape text is stored in a user field.

Save2Excel8

The captured data from the connection analysis can be saved to an Excel spreadsheet. Excel in this code is 2007 Excel and doesn’t do a lot of checking or error catching. It is there for convenience.

excel-output

Figure 5 Excel Output (PFD drawing)

Path Analysis (Depth-first)

The second part of the project was to demonstrate some of the common methods for analyzing path information. The basic flows are excerpts from Data Structures and Algorithms Using Visual Basic.NET, a Michael McMillan book that was written for VB.NET.

I thought it would be fun to convert the concepts to VBA and then use Visio to draw the constructs and use layering to show how the algorithms worked. The data is based on two mandatory arrays (vertex and edge) and an optional array that allowed me to force some of the shapes to specific places on the page.  A tutorial on this material goes well beyond what an article can cover. Mr. McMillan’s book is also referenced in the code.

path-analysis-depth-first

Figure 6 Path Analysis (depth first)

VBA Code

This code should not be considered as anything beyond demo code of some advanced concepts. When you open Visio’s VBA integrated development environment, you’ll see the following forms, modulas and classes:

application-objects

Figure 7 Application objects

Here’s a quick description of what each code file is about:

  • frmPath user interface
  • modDrawData the information used to initialize the three main arrays used to create the drawings used in the path analysis section
  • modFlowchartNavigator the basic code used in the v2007 sdk that demonstrates an approach to moving through a visio flowchart
  • modNavEnhanced an example of how analyzing a drawing might be enhanced using the two examples provided (Network Detail and PFD)
  • clsDistOriginal object storage
  • clsItemEdge object storage
  • clsItemPoint object storage
  • clsItempProbe object storage
  • clsVertex object storage
  • clsShapePos object storage
  • clsMyCollection string / array manipulation
  • clsMyGraph path analysis code

Have fun,

al

Download “Path Analysis in Visio VBA Code Sample and Diagram”

s!Aj0wJuswNyXlhXwn1leC9Gi3LjZY – Downloaded 6775 times – 103.00 B

  • Tweet
  • More
  • Pocket
  • Share on Tumblr
  • Print
  • Email

Related posts:

  1. Create Visio Flowcharts Programmatically
  2. Connect All Shapes to Each Other
  3. Using Visio 2010 Containers & Lists to Create Server Drilldowns with Excel Data

Filed Under: Code, Network Tagged With: Al Edlund, Code, Connectors

Previous Post: « Visio Squircles
Next Post: Wake Up Your Audience With Who Want’s to Be a Millionaire »

Reader Interactions

Comments

  1. philippe c says

    April 9, 2009 at 8:25 am

    I have tried to understand connections, but after two days I forget. That’s why I’ll wait for Visio Next Version.
    The same thing for a language as Python. It may be very powerful, but what is the use if you forget it after one week ?

  2. Visio Guy says

    April 9, 2009 at 1:59 pm

    Hi Philippe,

    I guess the best thing to do is develop some libraries that make connecting a matter of one call to one method.

    Visio 2007 has the new AutoConnect method, which makes coding somewhat easier than before.

    But I’ll agree with you. The raw Visio connection API is too elemental and I too forget some details that I always have to look up again!

  3. John Distai says

    April 10, 2009 at 2:02 pm

    Um, I have a dumb question. How do I actually open the code to view all the code pieces? I was able to open one piece of code, but it looked far too short for the functionality displayed. How do I view all those modules and classes?

    Thanks!

  4. Al Edlund says

    April 10, 2009 at 10:25 pm

    tools=>macros=>visual basic editor
    should look like the screen capture above, there’s also code in the form ….
    al

  5. simo says

    August 2, 2010 at 12:55 pm

    Hi!
    I am currently developing an application in VISIO.
    Please, I want to walk the path between two objects and save the path in a list, that contains the objects traversed

    so, from an object I want to achieve another object and save the path (objects) in a list

    thank you for helping me

    best regards
    Simo

  6. Visio Guy says

    August 2, 2010 at 1:46 pm

    Hi Simo,

    Have you downloaded the zip file and looked at the code? In Visio 2010, it is much easier because of the new ConnectedShapes and GluedShapes API methods.

    In older versions of Visio, you can look at the FromConnects collection on a shape, get the connectors that are connected to it, then look at the Connects collection of each connector to see which shape is on the other end. It’s kind of a pain in the butt, but it isn’t rocket science!

    The Visio SDK contains developer reference help on using the methods, as well as sample code.

  7. Paul says

    January 14, 2011 at 2:45 am

    Hello Al and Visio Guy,
    I enjoyed your article http://www.visguy.com/2009/04/08/path-analysis-in-visio/.
    Is there a way to use the VB macros to analyse an existing Visio GUI drawing? To show the connectivity like Simo asks.

    I read the Visio file Path_Analysis.vsd sample VBA code.
    Presumably I need to populate the data in module modDrawData with the data from the actual visio GUI objects.
    Are you aware of any code that can do this already?

    Have a good New Year
    Thanks for your help

    Paul
    System analyst
    ps. I’m not a programmer.

  8. Luis Contreras says

    March 12, 2011 at 3:51 am

    Hi!

    I am an end Visio 2007 user.

    I have this need: In a very large diagram with lots of connected shapes, when double clicking a certain shape, I need a zoom view window that shows that specific shape in the middle of the window; the shapes that located at left of the whole drawing that are connected to it, in the left side of the zoom window; and the shapes that located at right of the whole drawing that are connected to it, in the right side of the zoom window. Is there a tool to do that? Is there a way to do that or a person who can do it?

    Thanks.

  9. Andrei says

    September 14, 2014 at 5:27 pm

    Hello Visio Guy,
    for some time i`m walking through this topic “path analyse” and i cannot find and lets say it “a user friendly” solution for this.
    I`m not really good at coding, and when i started to look around the code – i got lost.

    Is there a way to draw the graphic by hand – use connection points and so-one (i was looking at ConnectedShapes and GluedShapes API methods but it seems something is escaping me) , select to ends of the drawn net and visualize the shortest path between them…

    I went through all the internet, and i cannot find a simple visual solution… 🙁

Leave a Reply Cancel reply

Primary Sidebar

Buy Über Rack Unit Dimension Line
Article — Purchase

Categories

Buy my book!

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Tag Cloud

A/V Artistic Effects BPM Code Connectors Control Handles Countries Custom Patterns Custom Properties Data Graphics Data Linking Data Visualization David Edson David Parker Fill Format Formulas Functions Geometry Gradient Images Links Maps Multi-shapes Network Programming repeating shapes Resources Right-Click Actions Scale Shape Data ShapeSheet ShapeSheet Formulas ShapeSheet Functions SharePoint shiny SmartShapes Sport Sports Text Themes Tools Transparency User-defined Cells Visio 2007 Visio SmartShapes

Top Posts & Pages

  • - Visio Shapes & Stencils
  • - Visio Templates & Drawings
  • Amazon AWS Visio Shapes
  • Dynamic Updating Org Charts in Visio!
  • Text on a Circle Visio Shape
  • Bubble Revision Shapes
  • Crayon Visio Network Shapes, Revisited
  • Sankey Diagram Shapes for Visio
  • Map of World
  • AV Engineering Diagrams with Symbol Logic ECAV

www.visguy.com - Visio Guy - since 2006

 

Loading Comments...