problems with shape-connectedshapes-method

Started by perry59, April 01, 2022, 05:46:36 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

perry59

according to https://msdn.microsoft.com/en-us/vba/visio-vba/articles/shape-connectedshapes-method-visio, invoking this function on a shape should give me a list of any other shapes connected to it, but my list is always zero. The shape in question is a grouped shape which just consists of a couple pieces of text and a connection point. This shape represents an electrical contact and the text is the contact number and signal name. Attached to the connection point of this shape is a connector which represents a wire and has it's own data associated with it.
All I need to know is if there is a connector attached to my contact shape and if so what is it's ID. Am I doing something fundamentally wrong?
Thanks for any tips.
Perry
what, me worry?

Paul Herber

I've just used the Page connections report from my utilities on this document and it reports as follows:

Wire G-275-001 -> Contact, equipment
Page connections report finished.

Perhaps the connector doesn't connect to where you think it does.

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

perry59

#2
That is correct, the "wire" does connect to "Contact, equipment".
However, I'd really rather not have to cycle though all the connections on a page if a user changes the signal text of the contact.
If the contact is selected I just want to know if there is something connected to it and if so it's ID.
Perhaps the shape-connectedshapes-method just does not work on this type of shape.
Perry
what, me worry?

perry59

It looks like I will have to iterate though every connect object on the page since the shape-connectedshapes-method only works with 1D shapes.
bummer, would be nice if any shape with a connection point knew if something was connected to it.
what, me worry?

Croc

#4
perry59,
You can use your own function instead ConnectedShapes. For example, this one:
Function ConnectedID() As Long
    Dim shp As Visio.Shape
    ConnectedID = 0
    If ActiveWindow.Selection.Count <> 1 Then Exit Function
    Set shp = ActiveWindow.Selection(1)
    If shp.FromConnects.Count <> 1 Then Exit Function
    ConnectedID = shp.FromConnects(1).FromSheet.ID
End Function


If multiple connectors are allowed, then so

Function Connected_ID(ByVal shp As Visio.Shape) As Variant
    If shp.FromConnects.Count < 1 Then Exit Function
    Dim arr() As Long
    ReDim arr(shp.FromConnects.Count - 1)
    For i = 1 To shp.FromConnects.Count
        arr(i - 1) = shp.FromConnects(i).FromSheet.ID
    Next
    Connected_ID = arr
End Function

Sub Test_Connected_ID()
    If ActiveWindow.Selection.Count = 0 Then Exit Sub
    Set shp = ActiveWindow.Selection(1)
    a = Connected_ID(shp)
    If IsArray(a) Then
        For i = LBound(a) To UBound(a)
            Debug.Print a(i)
        Next
    End If
End Sub