Now that I'm into the modern era of Visio, I re-looked at finding connectivity. After all, there are new features in Visio object model. What I didn't realize is that there are two ways to go about this...well, three, using the old style. One method uses
GluedShapes method and the other uses
ConnectedShapes method.
Thanks to David Parker for his efforts and code for both of these:
https://blog.bvisual.net/2009/09/16/listing-connections-in-visio-2010/I've modified both versions to be a little more general, and just serve as basic building block code.
Public Sub ListGluedConnections()
'Code lists shapes attached to connectors
'Original code developed by David Parker
'Code located @ https://blog.bvisual.net/2009/09/16/listing-connections-in-visio-2010/
'Minor code modification by Wapperdude, 2/4/2019
'
Dim shp As Visio.Shape
Dim connectorShape As Visio.Shape
Dim sourceShape As Visio.Shape
Dim targetShape As Visio.Shape
Dim aryTargetIDs() As Long
Dim arySourceIDs() As Long
Dim targetID As Long
Dim sourceID As Long
Dim i As Integer
For Each shp In Visio.ActivePage.Shapes
If shp.OneD Then
Debug.Print "Connector", shp.Name
arySourceIDs = shp.GluedShapes(visGluedShapesIncoming2D, "")
For i = 0 To UBound(arySourceIDs)
Set sourceShape = Visio.ActivePage.Shapes.ItemFromID(arySourceIDs(i))
Debug.Print "Src Shp: ", sourceShape.Name
Next
aryTargetIDs = shp.GluedShapes(visGluedShapesOutgoing2D, "")
For i = 0 To UBound(aryTargetIDs)
Set targetShape = Visio.ActivePage.Shapes.ItemFromID(aryTargetIDs(i))
Debug.Print "Tgt Shp: ", targetShape.Name
Next
Debug.Print ""
End If
Next
End Sub
Public Sub ListShapeConnections()
'Code finds shapes with outgoing connections and lists their target shapes.
'Original code developed by David Parker
'Code located @ https://blog.bvisual.net/2009/09/16/listing-connections-in-visio-2010/
'Code adapted by Wapperdude, 2/4/2019
'
Dim shp As Visio.Shape
Dim connectorShape As Visio.Shape
Dim sourceShape As Visio.Shape
Dim targetShape As Visio.Shape
Dim aryTargetIDs() As Long
Dim arySourceIDs() As Long
Dim targetID As Long
Dim sourceID As Long
Dim i As Integer
For Each shp In Visio.ActivePage.Shapes
If Not (shp.OneD) Then
arySourceIDs = shp.ConnectedShapes(visConnectedShapesOutgoingNodes, "")
For i = 0 To UBound(arySourceIDs)
If i = 0 And UBound(arySourceIDs) >= 0 Then
Debug.Print ""
Debug.Print shp.Name
End If
Set targetShape = Visio.ActivePage.Shapes.ItemFromID(arySourceIDs(i))
Debug.Print "Tgt Shp: ", targetShape.Name
Next
End If
Next
End Sub
Output from 1st code:Connector Relationship
Src Shp: Entity
Tgt Shp: Entity.19
Connector Relationship.60
Src Shp: Entity.19
Tgt Shp: Entity.37
Connector Dynamic connector
Src Shp: Entity
Tgt Shp: Entity.65
Connector Dynamic connector.106
Src Shp: Entity.65
Tgt Shp: Entity.83
Connector Dynamic connector.116
Src Shp: Entity.19
Tgt Shp: Sheet.85
Output from 2nd code:Entity
Tgt Shp: Entity.19
Tgt Shp: Entity.65
Entity.19
Tgt Shp: Entity.37
Tgt Shp: Sheet.85
Entity.65
Tgt Shp: Entity.83