Does GlueTo Delete Existing Glued Connectors..?

Started by contact_ankit86, January 31, 2013, 09:03:07 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

contact_ankit86

Hi,

i have two shapes (newshp and parentshp) I am trying to create a new dynamic connector and then gluing its BEGINX and ENDX with two mentioned shapes..

Here is what i am doing :

    Dim vsoCell5 As Visio.Cell
    Dim vsoCell6 As Visio.Cell
    Dim visConnector As Visio.Shape
    Set visConnector = pg.Drop(pg.Application.Documents.Item("ORGCH_U.VSS").Masters.ItemU("Dynamic connector"), 0#, 0#)
    Set vsoCell5 = visConnector.CellsU("EndX")
    Set vsoCell6 = newshp.CellsSRC(visSectionConnectionPts, newshp.CellsRowIndexU("Connections.Top"), 0)
    vsoCell5.GlueTo vsoCell6
   
    '''''''''''--------------------All working fine upto here


    Set vsoCell5 = visConnector.CellsU("BeginX")
    Set vsoCell6 = parentShp.CellsSRC(visSectionConnectionPts, parentShp.CellsRowIndexU("Connections.Bottom"), 0)
    vsoCell5.GlueTo vsoCell6

When above last statement is executed (vsoCell5.GlueTo vsoCell6 )
it deletes the already glued connector on top of the parentshp. I am not sure Why it is doing this..?

Any thoughts..?

Visio Guy

Hi C,

I'm not sure what's wrong, but have a look at this code snippet. I think it's fairly clean, and easy to follow.

It might help you to track down your issue, or just replace what you've got so far.

If I manually delete one of the Exec shapes, the connector does go away. Perhaps your code is running into this issue. My code doesn't, however.


Sub ConnectTwoOrgChartShapes()

  '// Setup: Open a document based on the Orgchart template.
  '//
  '// Drop two Exec shapes. Connects the bottom of one to the top
  '// of the other, then reverses the connection.

  '// Get the stencil:
  Dim stn As Visio.Document
  Set stn = Visio.Documents.Item("ORGCH_U.VSS")
 
  '// Get key masters:
  Dim mstExec As Visio.Master, mstConn As Visio.Master
  Set mstExec = stn.Masters("Executive")
  Set mstConn = stn.Masters("Dynamic connector")
 
  '// Drop two executives:
  Dim shpExec1 As Visio.Shape, shpExec As Visio.Shape, shpConn As Visio.Shape
  Set shpExec1 = Visio.ActivePage.Drop(mstExec, 4, 6)
  Set shpExec2 = Visio.ActivePage.Drop(mstExec, 4, 3)
 
  '// Drop a connector:
  Set shpConn = Visio.ActivePage.Drop(mstConn, 2, 2)
  '// Alternatively - saves having to get the master first:
  'Set shpConn = Visio.ActivePage.Drop(Visio.Application.ConnectorToolDataObject, 2, 2)
 
  '// Glue Begin to Exec 1:
  Call shpConn.Cells("BeginX").GlueTo(shpExec1.Cells("Connections.Bottom"))
  shpConn.CellsU("EndArrow").ResultIU = 4 '//...set some arrowhead so it's easy to see the direction
 
  '// Glue End to Exec 2:
  Call shpConn.Cells("EndX").GlueTo(shpExec2.Cells("Connections.Top"))
 
  Call MsgBox("Now let's reverse the connection!")
 
  '// Reverse the glue:
  Call shpConn.Cells("BeginX").GlueTo(shpExec2.Cells("Connections.Bottom"))
  Call shpConn.Cells("EndX").GlueTo(shpExec1.Cells("Connections.Top"))
 
  '// Cleanup:
  Set shpExec1 = Nothing
  Set shpExec2 = Nothing
  Set shpConn = Nothing
  Set mstExec = Nothing
  Set mstConn = Nothing
  Set stn = Nothing

End Sub
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

contact_ankit86

Hi,

Thanks a lot for looking into my query. But this too does not work for me. This code is creating a connection between shpExec1 and shpExec2 but at the same time it is deleting already glued connector on shpExec1 which is connected to some other shape.

Not sure whats happening..

Thanks,

contact_ankit86

Hi,

Did anyone get a chance too look into my query..?

Please respond

aledlund

just a guess from the side. It sounds like you're attempting to use the OrgChart wizard code. The OrgChart wizard will only allow a single connection between a position and a manager. That's why the later versions have a new connector for an indirect reporting function.
al

MacGyver

yeah when i attempted that code using a standard Dynamic Connector it worked fine, no issues.

Set visConnector = pg.Drop(Application.Documents.Item("Drawing4").Masters.ItemU("Dynamic connector"), 0#, 0#)