Question on Shape.Connects and Shape.FromConnects

Started by ImAPictureFormat, September 17, 2019, 10:10:55 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ImAPictureFormat

I'm creating a tree structure in Visio 2016, using some VBA to make connections between the Rectangles.

I have the following code that I'm using to create a new connector and glue it to the "parent" (closer to the top of the page) and "child" (below the parent) Rectangles.


Set connector = ActivePage.Shapes.ItemFromID(connectorID)
Set connBeginCell = connector.CellsU("BeginX")
Set connEndCell = connector.CellsU("EndX")
Set parentCell = parent.CellsSRC(7, 0, 0)
Set childCell = shp.CellsSRC(7, 2, 0)
           
connBeginCell.GlueTo parentCell
connEndCell.GlueTo childCell


What I was hoping I do later on was then use the .FromSheet and .ToSheet properties of the .FromConnects and .Connects members of a shape to trace through the tree. Something like:

' Tracing through the tree upward
' Assuming you have a child that has already been declared as a Visio.Shape
Dim parent as Visio.Shape
Set parent = child.FromConnects(1).FromSheet ' this would hopefully be the same parent that was set in the gluing operations earlier on

' Or, tracing through the tree downward
' Assuming you have a parent already
Dim child as Visio.Shape
Set child = parent.Connects(1).ToSheet ' this would hopefully be the same child that was set in the gluing operations earlier on


What I am actually seeing is that all the connections I created via gluing are ending up the .FromConnects of all the Rectangles (parents and children), and the .Connects for every Rectangle is empty. In addition, the .FromSheet of any FromConnect is set to the connector object and not the desired Rectangle. An example:

' Assuming you have the child already
Dim iHopeThisIsTheParent as Visio.Shape
Set iHopeThisIsTheParent = child.FromConnects(1).FromSheet
MsgBox iHopeThisIsTheParent.Name  ' I want this to say "Rectangle", but it actually says "Dynamic connector"


Is there a way to programmatically create the connections so that I can trace up and down the tree?

Thanks in advance! :)

wapperdude

Connectivity  info is in the connector, not the 2D shapes.

However, you can use the glued to method.  It is 2D shape based.  See http://visguy.com/vgforum/index.php?topic=8912.0

Hope this helps.
Visio 2019 Pro

ImAPictureFormat

That was exactly that I needed to get what I wanted. Thanks!