Report of source process, target process, connector text

Started by PaulLondon, November 12, 2013, 10:08:13 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

PaulLondon

Hi

I have a Visio file consisting of around 100 process boxes, each of which is labelled, and around 400 connectors from process A to process B, only some of which are labelled.  I want a macro to pull off a report that has three columns: source process text, target process text and connector text. 

I have tried two ways of doing this but neither way seems to give me what I need.  The code I'm using is below.

Approach one: loop through all the connectors and use the ToSheet and FromSheet properties.  This will give me the target process text and the connector text, but I can't make it give me the source process text - the FromSheet property gives me the connector text, not the source process text and I can't find a property that does give me the source process text.

Approach two: loop through all the processes and use the visConnectedShapesOutgoingNodes property.  This will give me the source process text and the target process text, but I can't find a property that gives me the connector text.

Code for approach 1:
            Sub GetConnectorInfo2()
             
                Dim vsoConnects As Visio.Connects
                Dim vsoConnect As Visio.Connect
                Dim vsoConnectTo As Visio.Shape
                Dim vsoConnectFrom As Visio.Shape
                Dim intCurrentConnectIndex As Integer
               
                Set vsoConnects = ActivePage.Connects
             
                For intCurrentConnectIndex = 1 To vsoConnects.Count
           
                    Set vsoConnect = vsoConnects(intCurrentConnectIndex)
                    Set vsoConnectTo = vsoConnect.ToSheet
                    Set vsoConnectFrom = vsoConnect.FromSheet
           
                    'Try to print the source process text, the target process text and the connector text
                    Debug.Print "Source process: "; vsoConnectFrom.Text; " | Target process: "; vsoConnectTo.Text; _
                    " | Connector text: "; vsoConnectFrom.Text
                   
                Next intCurrentConnectIndex
             
            End Sub

Code for approach 2: NB I know this doesn't do the looping, but I stopped fiddling with it when I couldn't get the properties I needed.  I can add the looping if I can figure out how to get the property.
            Sub ConnectedShapes_Outgoing_Example()
       
              ' Get the shapes that are connected to the selected shape
               ' by outgoing connectors.
                   Dim vsoShape As Visio.Shape
                   Dim lngShapeIDs() As Long
                   Dim intCount As Integer
           
                   Set vsoShape = ActiveWindow.Selection(1)
                         
                   lngShapeIDs = vsoShape.ConnectedShapes(visConnectedShapesOutgoingNodes, "")
                   For intCount = 0 To UBound(lngShapeIDs)
                      Debug.Print "Source process: "; vsoShape.Text; " | Target process: "; _
                      ActivePage.Shapes.ItemFromID(lngShapeIDs(intCount)).Text

                   Next intCount

               End Sub           

Any help you can give on this, greatly appreciated.

Thanks
Paul

aledlund

paul,
could you share a small diagram of what you are doing (possibly as little as four processes and two or three connectors)?
tks,
al

wapperdude

If you haven't already, take a look at this post:  Finding both ends of a connector with VBA, http://visguy.com/vgforum/index.php?topic=2530.0

VisioGuy's response points to 3 links.  There might be something helpful.  My approach to the problem would be to search thru the connectors, find what's attached at each end, then query each shape for the desired text.  It's basically the same approach that you've tried, but, checks the specific shapes.

HTH
Wapperdude
Visio 2019 Pro

PaulLondon

Al - thank you for your response.  I've attached a simple diagram with four processes.  With the attached diagram, what I'm looking for is a report that looks like this (the order of the lines (and actually the columns, as well) doesn't matter in the report):

Process A | Process B | Order
Process A | Process D | Preview
Process B | Process D | Stock
Process C | Process A | Invoice

Wapperdude - thank you.  I'll take a look.


Yacine

Hi Paul,

presuming that the connects collection is always sorted by the connector shapes, you can run through this collection and parse always two consecutive connect objects, as long as their .fromsheet.id property is the same.

Sub listConnections()
For Each cn In ActivePage.Connects
    If prevConnID = cn.FromSheet.ID Then
        Debug.Print prevText; " --- "; prevConn; " --> "; cn.ToSheet.Text
    Else
        prevConnID = cn.FromSheet.ID
        prevConn = ActivePage.Shapes(cn.FromSheet.ID).Text
        prevText = cn.ToSheet.Text
    End If
Next cn
End Sub
Yacine