Visio Guy

Visio Discussions => Programming & Code => Topic started by: perry59 on February 23, 2020, 10:00:54 PM

Title: get name of item connector is connected to
Post by: perry59 on February 23, 2020, 10:00:54 PM
I know that this has been discussed before, so please pardon the repeat.
As the title says, I want to get the name of an item that a connector is connected to, BUT I want to do strictly within the shapesheet. I know it can be done via a macro, but I don't want macro's in my shapes. Previously it was said that this is not possible, but that discussion is several years old, perhaps things have changed?
Title: Re: get name of item connector is connected to
Post by: wapperdude on February 24, 2020, 01:16:30 AM
Nope.  Still no shapesheet function to do that.
Title: Re: get name of item connector is connected to
Post by: perry59 on February 24, 2020, 02:00:59 AM
I thought so, bummer!
Title: Re: get name of item connector is connected to
Post by: vojo on February 24, 2020, 03:51:26 AM
in general, shapes are not aware of other shapes around or attached to.
I believe the best you can do is to compare pinx and piny of the connector to the pinx and piny + offsets of the connection point.
if equal, then that connector is attached to connection point Q.

The generalized case would have lots of tedious math...ao I would not try do that.
Title: Re: get name of item connector is connected to
Post by: OldSchool1948 on March 24, 2020, 05:10:33 PM
I use a subroutine stored in a module that uses the GluedShapes method as illustrated in the below code snippets to return the Shape IDs for incoming and outgoing 2D shapes on a page, and then parses though them


Set vsoPage = thisDocument.Pages

'// Get all shapes on that page
Dim vsoSelection As Visio.Selection
Set vsoSelection = vsoPage.CreateSelection(visSelTypeAll, _
                                visSelModeSkipSuper, vsoPage)

For i = 1 to vsoSelection.Count

     If isConnector(Shape) = true then   ' A custom function that identifies connectors shapes

         Dim vsoConnector as Visio.Shape
         Set vsoConnector = vsoSelection(i)

         '// Grab the Shape.IDs for all Incoming & Outgoing glued shapes
         Dim srcArrIDs() As Long
         srcArrIDs = vsoConnector.GluedShapes(visGluedShapesIncoming2D, "")

         Dim dstArrIDs() As Long
         dstArrIDs = vsoConnector.GluedShapes(visGluedShapesOutgoing2D, "")

         '// Parse through Source Shapes
         For srcAryCntr = 0 To UBound(srcArrIDs)
       
              Dim srcShape As Visio.Shape
              Set srcShape = vsoPage.Shapes.ItemFromID(srcArrIDs(srcAryCntr))

         '// Parse through Source Shapes
         For dstAryCntr = 0 To UBound(dstArrIDs)

              Dim dstShape As Visio.Shape
              Set dstShape = vsoPage.Shapes.ItemFromID(dstArrIDs(dstAryCntr))