Results 1 to 2 of 2
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Andover, MA USA
    Thanked 0 Times in 0 Posts

    what is each end connected to? (Visio 2002)

    I am convinced that what I need is there in the ShapeSheet but I haven't found it yet...

    I'm looking for a way to determine the shape to which each end of a connector is attached. I know the coordinates of the endpoint are there (BeginX/BeginY/EndX/EndY) but what I really want is the ID of the shape at each end of the connector.

    Any idea where I will find these values?

  2. #2
    Star Lounger
    Join Date
    Jan 2001
    Andover, MA USA
    Thanked 0 Times in 0 Posts

    Re: what is each end connected to? (Visio 2002)

    I'm responding to my own post in case what I ended up doing is useful to someone else. As noted in the previous post, I needed to figure out what shape was at each end of a dynamic connector. I couldn't find any way to do this within the shapesheet so I bit the VBA bullet and, while it took me a while to work out exactly what I had to do, the code below works nicely.

    What I wanted to accomplish specifically was to take the contents of a custom property field in the shape at each end of a dynamic connector and embed their values into two custom property fields in the connector itself. (NOTE: you must have the appropriate custom property fields defined before running this code.)
    = = = = = = = = = = = = = =
    <pre>Sub CalculateLinkEnds()
    '1) iterates through all shapes on page
    '2) ignores all shapes except those whose name starts with "HCG Line"
    '3) for every HCG Line that is connected on both ends, places contents of
    ' custom properties field (Prop.Number) from shape that HCG Line is connected to
    ' into a custom property field in HCG Line (Prop.From at start; Prop.To at end)
    '4) for HCG Lines that are not connected at both ends, adds line to selection set
    ' so that all un-connected lines are highlighted when subroutine ends

    Dim i As Integer

    Dim shpCurrent As Visio.Shape
    Dim collEndPoints As Visio.Connects
    Dim shpFrom As Visio.Shape
    Dim shpTo As Visio.Shape

    'if anything is selected, turn it off

    For i = 1 To ActivePage.Shapes.Count
    Set shpCurrent = ActivePage.Shapes.Item(i)

    Select Case Left(shpCurrent.Name, 8) 'First 8 char. contains shape name without .ID
    Case "HCG Line"
    'Get connection collection for current shape
    Set collEndPoints = shpCurrent.Connects

    If collEndPoints.Count = 2 Then 'both ends are connected
    Set shpFrom = collEndPoints(1).ToSheet
    shpCurrent.Cells("Prop.From").Formula = shpFrom.Cells("Prop.Number").Formula

    Set shpTo = collEndPoints(2).ToSheet
    shpCurrent.Cells("Prop.To").Formula = shpTo.Cells("Prop.Number").Formula
    'Add current shape to selection set
    ActiveWindow.Select shpCurrent, visSelect
    End If
    End Select

    If ActiveWindow.Selection.Count > 0 Then
    MsgBox ("one or both ends of selected shape(s) are not connected")
    End If

    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts