-2

Is there any way to read the process flow of Visio flow. if we have Visio document like the below Can I read the process like From Begin to Process 1 Then From Process 1 to Decision 1. If the Decision 1 is Yes then Process 3 else Process 2 . From Process 3 to END. From to Process 2 to Decision 2 etc..

enter image description here

Is that possible to read like the above using macro in Visio or using C# from Visual Studio.

Tamas Szoke
  • 4,128
  • 3
  • 19
  • 30
  • It's possible, but it takes a bit of understanding of graph theory, and then you have to apply that to Visio's object model. But yes, it's possible, I've written code that does something similar, before. – Jon Fournier Mar 11 '20 at 13:58

1 Answers1

1

Visio has an automation model that allows you to write code that will do what you want to do. Visio has built-in VBA (Visual Basic for Applications), so you can quickly get started fiddling with code. Whereas creating a VSTO add-in in C# or VB.NET takes a lot more effort just to get started.

As long as the connectors are properly glued to the shapes, you can trace the structure of the diagram. It's not really obvious how to do this, but I can offer a few tips off the top of my head. If nothing else, the terms that I mention below will help in searching for code samples and API references.

The boxes are called "2D" shapes in Visio and the connectors are called "1D". You can detect "1D" shapes by querying the shape.OneD property.

2D shapes have "FromConnects" objects and 1D shapes have "Connects" objects. Connects objects essentially encapsulate the glued end of the connector. With a Connects object, you can get the end of the connector that is glued (Begin or End), and what it is glued to (a particular connection point, or an entire shape).

In this way you can build a list of connections that note the from-box and the to-box, and thus you can understand the structure of the diagram.

You can find starting points by looking for boxes that have no incoming connections. In Visio parlance, that means no connectors have their connector End glued to a shape. (Connectors have Begin and End ends).

I'm sure I have samples laying around somewhere, but I'm not in a place that I can search for them at the moment. Here is some rough, untested code that might help you to get started:

Public Sub AnalyzePage

  Dim pg As Visio.Page
  Set pg = Visio.ActivePage

  Dim shp As Visio.Shape
  For Each shp in pg.Shapes

    If (shp.OneD) Then
      '// This is a connector:
      '// We could examine shp.Connects to find out which
      '// boxes it is glued to.
    Else
      '// This is not a connector...a box:
      If (shp.FromConnects.Count > 0) Then
        '// FromConnects are the other side of Connects. We can look
        '// at each FromConnect object for this shape and determine if
        '// the connector is incoming or outgoing from this shape, and
        '// (with a bit of work) figure out the box on the other end
        '// of the connector.
      End If
    End If

  Next shp


End Sub
Visio Guy
  • 171
  • 4