Unusual Gluing Behavior

Started by OldSchool1948, October 24, 2016, 09:46:00 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

OldSchool1948

See the modShapeMgr module in the attached.  I wrote a subroutine that uses Visio's dynamic connector to automatically (1) drop a single connector on a page or (2) drop connectors between two or more shapes. If you right-click on a server shape, you'll see the menus and menu options.  If you right-click on a connector shape, you'll see custom menus to "swap line ends" and "change connector types."

I'm using two types of shapes (1) server shapes provided out-of-the-box (OOTB) by Microsoft and (2) custom built virtual machine (VM) shapes provided my Microsoft.  Sometimes the connector glues the begin-point and end-point to a shape's side as expected, but not always.  For example, in the attached file, gluing a connector between the "Application Server VM" shape and "Application Server VM multi" shape work as expected.

When either of them is connected to any other VM shape, the dynamic gluing behavior is unpredictable, that is, the begin-point or end-point connects to the center of a shape and not on an edge.  (Gluing two or more OOTB shapes work as expected.) I cannot figure out why this is happening.  Any advice would be much appreciated.

OldSchool1948

I've been programming with VBA and Visio for about 4 months and can usually figure these things out though Google searches, this blog, and homework :-).  The odd thing, if I drop a "right-angle" or "curved" connector, things work as expected.  It's only "straight-line" connectors and only with some VM shapes.  By the way, the VM shapes from Microsoft's Azure cloud collection. 

I'm only asking for advice if anyone has experienced a similar problem with gluing automation.   

wapperdude

#2
I didn't go thru your code thoroughly, but, what struck me as strange is the method that you use to glue the connector to the various shapes.  Unless I'm looking at the drawing incorrectly, it seems that you want to glue to connection points on the edge of the shapes, but your "GlueTo" references PinX.  The fact that the connectors end up on a connection point strikes me as more coincidence than by design.

Normally you would reference a specific connection point.  The code would look something like this:
   
    Set vsoCell1 = Application.ActiveWindow.Page.Shapes.ItemFromID(3).CellsU("BeginX")          'Connector point end
    Set vsoCell2 = Application.ActiveWindow.Page.Shapes.ItemFromID(179).CellsSRC(7, 2, 0)      'Shape connection point
    vsoCell1.GlueTo vsoCell2


If you don't really care about gluing to a connection point, you might try something like this, which just glues to the shape (at some point of contact):

    Set vsoCell1 = Application.ActiveWindow.Page.Shapes.ItemFromID(3).CellsU("BeginX")
    vsoCell1.GlueToPos Application.ActiveWindow.Page.Shapes.ItemFromID(178), 0.64696, 0#


You can get this code using the macro recorder.

HTH
Wapperdude
Visio 2019 Pro

OldSchool1948

Quote from: wapperdude on October 26, 2016, 04:46:57 AM
I didn't go thru your code thoroughly, but, what struck me as strange is the method that you use to glue the connector to the various shapes.  Unless I'm looking at the drawing incorrectly, it seems that you want to glue to connection points on the edge of the shapes, but your "GlueTo" references PinX.  The fact that the connectors end up on a connection point strikes me as more coincidence than by design.

Normally you would reference a specific connection point.  The code would look something like this:
   
    Set vsoCell1 = Application.ActiveWindow.Page.Shapes.ItemFromID(3).CellsU("BeginX")          'Connector point end
    Set vsoCell2 = Application.ActiveWindow.Page.Shapes.ItemFromID(179).CellsSRC(7, 2, 0)      'Shape connection point
    vsoCell1.GlueTo vsoCell2


If you don't really care about gluing to a connection point, you might try something like this, which just glues to the shape (at some point of contact):

    Set vsoCell1 = Application.ActiveWindow.Page.Shapes.ItemFromID(3).CellsU("BeginX")
    vsoCell1.GlueToPos Application.ActiveWindow.Page.Shapes.ItemFromID(178), 0.64696, 0#


You can get this code using the macro recorder.

HTH
Wapperdude

First, thanks for the response.  I also felt using PinX/PinY odd, but they work perfectly with Visio's out-of-the-box shapes; and with two of Microsoft's Azure cloud shapes.  Admittedly, I have no idea why.  I thought if I connected to an "edge" or to a specific connection point, it would make the connector static and I need dynamic connectors.  Is that not true?

wapperdude

Depends upon what you mean by dynamic.  Gluing to a connection point "anchors" the connector end, but the routing will still be dynamic.  If you want the connector end "to walk" around the perimeter of the shape, then don't glue to connection point.  Either case, if you re-arrange, add/delete shapes, the connector may adjust its routing.

Some additional info:
    https://msdn.microsoft.com/en-us/library/office/ff768581.aspx
    http://boxesandarrows.com/visio-glue-not-for-sniffing-special-deliverable-13/
   
Wapperdude
Visio 2019 Pro

OldSchool1948

I'm looking for dynamic gluing as described in the article.  I do want the connector to walk around the edge of the shapes. 

wapperdude

OK. 

The connection points were added as a result of gluing attempts?  I tried manually to dynamically glue to the Web Server VM shape.  No luck.  The connector just glues to the literal PinX, PinY location rather than the walk-around dynamic gluing.

Tried a variety of things such as selecting group only, deleting all existing connection points, locking the group, etc.  Nothing helps.  Started pushing down into the shape and some of the subshapes become quite complex with multiple geometry sections.  For example the little globe shape.  Each "line" in the shape is a separate geometry section in the "globe" subshape.  I deleted the globe, and dynamic gluing works.  Conclusion:  some of these shapes are too complex and interfere with Visio's dynamic gluing capability.

Wapperdude
Visio 2019 Pro

OldSchool1948

First off, thanks for your help.  I've noticed that help a lot of us "newbies" and it is greatly appreciated. 

I figured things by first using a plain dynamic connector with the new Azure shapes and things worked as expected.  I then rewrote the DropConnector subroutine and integrated each of my customization one at a time until I discovered the culprit was these lines of code:

Set celCell = shpConnector.Cells("ShapeRouteStyle")
celCell.Formula = 16 'Center to Center

I changes the cell formula to the following and everything is working as expected:

celCell.Formula = 2 'Straight

Once again, thanks for your help.

Regards,

JP