Automation: Removing a connection (unGlue)

M

M@

Hey,

I'm looking for a way to unglue two shapes on a page, using automation. As
far as I am aware there is no 'unglue' method for a shape?

Background:
I am using the ConnectionsAdded event which is triggered when a new
connection is added to the connects collection.
When a connection is made between two shapes (by a user) I am validating the
connection and would like to automatically remove the connection if it is
not validated.

eg. The user connects a Dynamic Connector to a Shape. The ConnectionsAdded
event fires then VBA code determines the connection is NOT valid. The
dynamic connector should then automatically disconnect & the end making the
connection is preferably left floating on the page.

Version: Visio Pro 2002 SR-1
Development Environment: Visio's VBA
 
M

Markus Breugst

Hi M@,

perhaps you could simply set the BeginX, BeginY, EndX, EndX cells to fixed
values.

Here's a short VB example.

Public Sub Unglue()
Dim connectionShape As Shape
Dim beginX As Double
Dim beginY As Double
Dim endX As Double
Dim endY As Double

Set connectionShape = *** the connection shape to be unglued ***
beginX = connectionShape.Cells("BeginX").ResultIU
beginY = connectionShape.Cells("BeginY").ResultIU
endX = connectionShape.Cells("EndX").ResultIU
endY = connectionShape.Cells("EndY").ResultIU
connectionShape.Cells("BeginX").ResultIU = beginX - 0.2
connectionShape.Cells("BeginY").ResultIU = beginY - 0.2
connectionShape.Cells("EndX").ResultIU = endX - 0.2
connectionShape.Cells("EndY").ResultIU = endY - 0.2
End Sub

Hope this helps.

Best regards,
Markus
 
P

Phil Spiby

I use the Undo method on the application to just undo the operation which
caused the connection.

You may have to catch a -2032463809 error code, if the undo cannot be
performed.

Phil
 
M

M@

Thanks Markus & Phill, both great suggestions.

After posting this I decided to just change the color of the Dynamic
Connector shape to indicate an invalid connection. With your suggestions
though I can have it actually remove the connection, much nicer. :)
 
M

Markus Breugst

Hi M@,

changing the color is exactly the thing we also do. Additionally, we write
an error message into the "Comment" cell of the connection shape. In this
way the user sees what's wrong with the connection when moving the mouse
pointet onto the shape. As soon as the user reroutes the shape correctly,
the color changes from red to black, and the error message disappears.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top