Visio Guy

Visio Discussions => Programming & Code => Topic started by: prasanna2j on September 27, 2011, 02:08:48 PM

Title: Identify Connections to 2D shapes
Post by: prasanna2j on September 27, 2011, 02:08:48 PM
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
Title: Re: Identify Connections to 2D shapes
Post by: aledlund on September 27, 2011, 04:13:26 PM
there is probably someting in here that will help
http://www.visguy.com/2009/04/08/path-analysis-in-visio/
al
Title: Re: Identify Connections to 2D shapes
Post by: prasanna2j on September 28, 2011, 02:02:02 PM
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
Title: Re: Identify Connections to 2D shapes
Post by: DJozef87 on September 29, 2011, 08:02:25 AM
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 
Title: Re: Identify Connections to 2D shapes
Post by: aledlund on September 29, 2011, 12:24:49 PM
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
Title: Re: Identify Connections to 2D shapes
Post by: vojo on September 29, 2011, 01:19:51 PM
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.
Title: Re: Identify Connections to 2D shapes
Post by: DJozef87 on September 29, 2011, 03:09:16 PM
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
Title: Re: Identify Connections to 2D shapes
Post by: aledlund on September 29, 2011, 03:19:34 PM
These aren't cells (shpIDs = shp.GluedShapes(visGluedShapesIncoming2D, "")), they are methods. It's a derived call.
al
Title: Re: Identify Connections to 2D shapes
Post by: DJozef87 on September 29, 2011, 04:02:27 PM
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
Title: Re: Identify Connections to 2D shapes
Post by: vojo on September 29, 2011, 06:52:56 PM
in 2003

Cell Begtrigger and Endtrigger cells.....parse their values and react as appropriate....sort of filters the shape types for you
Title: Re: Identify Connections to 2D shapes
Post by: Jumpy on September 30, 2011, 07:16:05 AM
What happend to the shapes connects-collection. Can't u use that in VBA?
Title: Re: Identify Connections to 2D shapes
Post by: DJozef87 on September 30, 2011, 12:26:58 PM
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
Title: Re: Identify Connections to 2D shapes
Post by: Jumpy on September 30, 2011, 01:04:19 PM
shp.Connect(i).ToShape or was it .ToSheet shpuld give you the shape directly without the detour via Tocell.Shape
Title: Re: Identify Connections to 2D shapes
Post by: DJozef87 on September 30, 2011, 01:19:46 PM
yes Jumpy,
shp.Connect(i).ToSheet return the same result :)
Thanks
Browser ID: smf (is_webkit)
Templates: 1: Printpage (default).
Sub templates: 4: init, print_above, main, print_below.
Language files: 1: index+Modifications.english (default).
Style sheets: 0: .
Hooks called: 84 (show)
Files included: 25 - 925KB. (show)
Memory used: 774KB.
Tokens: post-login.
Cache hits: 8: 0.00111s for 22,302 bytes (show)
Cache misses: 2: (show)
Queries used: 11.

[Show Queries]