Identify Connections to 2D shapes

Started by prasanna2j, September 27, 2011, 02:08:48 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

prasanna2j

Hi,

Any code to list which 1D connectors are attached to a 2D shape.

I have a code that lists the source and target 2D shape for a 2D shape, but not a 1D shape source/target!

This is what I have:

Public Sub ListNextConnections()
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
        If shp.CellExists("Prop.NetworkName", Visio.visExistsAnywhere) Then
            Debug.Print "Shape", shp.Name, shp.Cells("Prop.NetworkName").ResultStr("")
            arySourceIDs = shp.ConnectedShapes(visConnectedShapesOutgoingNodes, "")
            For i = 0 To UBound(arySourceIDs)
                Set sourceShape = Visio.ActivePage.Shapes.ItemFromID(arySourceIDs(i))
                If sourceShape.CellExists("Prop.NetworkName", Visio.visExistsAnywhere) Then
                    Debug.Print , "<", sourceShape.Name, sourceShape.Cells("Prop.NetworkName").ResultStr("")
                End If
            Next
            aryTargetIDs = shp.ConnectedShapes(visConnectedShapesIncomingNodes, "")
            For i = 0 To UBound(aryTargetIDs)
                Set targetShape = Visio.ActivePage.Shapes.ItemFromID(aryTargetIDs(i))
                If targetShape.CellExists("Prop.NetworkName", Visio.visExistsAnywhere) Then
                    Debug.Print , ">", targetShape.Name, targetShape.Cells("Prop.NetworkName").ResultStr("")
                End If
            Next
        End If
    End If
Next


Any way we can tweak the code to list the incoming/outgoing 1D connectors????

Regards
prasanna2j

aledlund


prasanna2j

I got some code on microsoft website, which kinda solves my problem. Here it is



Public Sub GetGluedShapes()
'Use Shape.GluedShapes to get the shapes that are glued to a shape
    Dim shp As Visio.Shape
    Dim shpIDs() As Long
    Dim i As Integer

    'MsgBox "GluedShapes"
    If ActiveWindow.Selection.Count = 0 Then
        MsgBox ("select a shape with connections")
        Exit Sub
    Else
        Set shp = ActiveWindow.Selection(1)
    End If

    shpIDs = shp.GluedShapes(visGluedShapesIncoming1D, "")
    'MsgBox "Incoming 1D shapes"
    For i = 0 To UBound(shpIDs)
        MsgBox ActivePage.Shapes(shpIDs(i)).Name
    Next

    shpIDs = shp.GluedShapes(visGluedShapesOutgoing1D, "")
    'MsgBox "Outgoing 1D shapes"
    For i = 0 To UBound(shpIDs)
        MsgBox ActivePage.Shapes(shpIDs(i)).Name
    Next

    shpIDs = shp.GluedShapes(visGluedShapesIncoming2D, "")
    'MsgBox "Incoming 2D shapes"
    For i = 0 To UBound(shpIDs)
        MsgBox ActivePage.Shapes(shpIDs(i)).Name
    Next

    shpIDs = shp.GluedShapes(visGluedShapesOutgoing2D, "")
    'MsgBox "Outgoing 2D shapes"
    For i = 0 To UBound(shpIDs)
        MsgBox ActivePage.Shapes(shpIDs(i)).Name
    Next
End Sub

DJozef87

#3
hello  prasanna2j,

I am trying to list the incoming/outgoing 1D connected shapes to a selected Shape, your example is very useful but I have the "invalid sheet identifier" error... Any idea how to fix this ?

Thank you 

aledlund

Just as an assumption I'd start by examining the version of Visio, a lot of enhancements to analyzing connectivity came in the v2010 version.
al

vojo

One thing that might make the task easier is that when a connector is connected, the shapes the "from" and "to" cells are populated.    could just walk thru all shapes and look in those cells for where coming from and where going.

Just something that might help.

DJozef87

I have Visio 2010 version...
I think that's a good idea to look at these cells... Is there any documentation or a link in which I can find all the cells related to the Shape object ?? because I can't find these "from" and "to" cells

aledlund

These aren't cells (shpIDs = shp.GluedShapes(visGluedShapesIncoming2D, "")), they are methods. It's a derived call.
al

DJozef87

I was talking about vojo's post, maybe I misunderstood what he meant.

The GluedShapes method : GluedShapes(visGluedShapesIncoming1D, "") does not seem to work well for me and I need to list connected shapes to my selected shape

vojo

in 2003

Cell Begtrigger and Endtrigger cells.....parse their values and react as appropriate....sort of filters the shape types for you

Jumpy

What happend to the shapes connects-collection. Can't u use that in VBA?

DJozef87

Now it works
I parse all the connections in my Visio page, for each one I get the shp.Connects.Count and with a For loop I get the shp.Connect
(i).ToCell.shape and so on I get all the linked shapes with that connection

Jumpy

shp.Connect(i).ToShape or was it .ToSheet shpuld give you the shape directly without the detour via Tocell.Shape

DJozef87

yes Jumpy,
shp.Connect(i).ToSheet return the same result :)
Thanks