Design-Drawing Home  
Drawing Program
ISSN 1441-5585

Search...

Home
Articles
Software Catalog
Book Store
About
Advertising
Newsletter

 

 

Named Connections

David A Edson

As if we haven't had enough of named connections of various kinds! In Visio however, named connections can work to your professional advantage without raising questions or inspiring front page news.

Greetin’s an’ weel met!!! Grand tae be bak wi’ ye again…

Let's take a wee bit of time to look at a problem that many o’ ye folk face when creating connected diagrams.

"When a user of my custom solution Glues a Control Handle Shape on "A" to a Connection Point on Shape "B", how can I programmatically tell that the connection is valid? That is, how can I tell that he or she has glued the Control Handle to the correct Connection Point rather than a Connection Point which might be an illegal connection in my logical or physical diagram?"

In earlier versions of Visio, if you were to look into a SmartShape’s ShapeSheet you would see a Connection Points section with a row for each connection point that has been established on the shape. Programmatically, you could use Visio’s FromCell and ToCell properties of the Connects Object to ascertain what Cell Shape "A" had connected to on Shape "B", but that was all. Under Visio 5.0, you now have the ability to name each connection row in a ShapeSheet’s Connection Points Section, and furthermore, you can store additional information in the A through D cells of that named row.

Now, by default, when you create a new connection point on a shape, there are only the older default X and Y cells shown. To enable the advanced features, select the row in the ShapeSheet, and then right-clicking, select the "Change Row Type" short-cut menu item. This will enable the naming of the row and add the A through D data storage cells to the Connection Point row.

With this feature now enabled you may store whatever data is appropriate in the 4 storage cells. A typical case might be to store the IP address, and other Network connection information on a PC being connected to a network in the connections row of that Network Equipment shape for that particular connection. Another connection point on that piece of equipment might be reserved for connection power input, which might carry information such as voltage and cycle settings for international use. Of course it would be illegal, and quite possibly hazardous to the equipment to attempt to connect the network cable to the power input port, and therefore you will want to validate that the equipment is properly connected.

The example that I am going to share with you is illustrated below:

 Moving the source connection from one connection point to another on the target shape changes the connection report on the source shape.

All information discussed here is included in a downloadable Visio drawing file.

As you work with the drawing and glue and unglue the control handle to and from the connection points on the adjacent shape note how the Source Shape’s text continually reflects the validity and status of the glued connection.

For this example, I have attached two Custom Properties to the Target Shape. The Connection Points’ "A" Cells take their values from a reference to these Custom Property Cells. The User can set the values for each of the Custom Property items and this will be associated with the applicable Connection item. The automation code in the FindGlueItem() Subroutine is triggered whenever the value of the Source Shape’s Control Handle’s "X" cell is changed. This is accomplished by the following line of code in one of the Source Shape’s User Cells: =DEPENDSON(Controls.X1)+RUNADDON("FindGlueItem").

The mechanism is this… Whenever the user moves the Source Shape’s Control Handle, the User Cell User.TriggerChange is evaluated and then the VBA function FindGlueItem() is executed. The code for this function is listed below.

Public Sub FindGlueItem()
' Begin declaration of variables and type casting
Dim shSource As Visio.Shape
' Source (Purple) Shape
Dim shTarget As Visio.Shape
' Target (Yellow) Shape
Dim ceConnPt As Visio.Cell
' Connection Point X cell in the Target Shape
Dim ceInfo As Visio.Cell
' User.GluedTo Cell in the Source Shape
Dim connsColl As Visio.Connects
' Source Shape's Connects Collection
Dim connsItm As Visio.Connect
' Connect Item in the Connects Collection
Dim partCell As String
' String to hold the partial Cell name
Dim cellNme As String
' String to hold the fully qualified Cell name
Dim GluedToString As String
' String to hold the value in fully qualified Cell

' Begin executable code
Set shSource = Visio.ActivePage.Shapes.Item("Source")
' Get a reference to the Source Shape by name as an item
' of the Shapes collection on the Active Page
Set ceInfo = shSource.Cells("User.GluedTo")
' Get a reference to the User.GluedTo cell in the Source Shape
' from the Cells property of the Shape
Set connsColl = shSource.Connects
' Get the Connects collection of the Source Shape
Set shTarget = connsColl.ToSheet
' Get a possible reference to the Target Shape by getting
' the ToSheet property of the Connections collection
If Not (shTarget Is Nothing) Then
' If there is actually an item in the ToSheet property
' of the Connections collection then this means that there is
' a valid glued connection and the Target Shape reference is
' returned
Set connsItm = connsColl.Item(1)
' Get the first item in the Connects collection as the glued
' connection
Set ceConnPt = connsItm.ToCell
' Get the cell that is connected by a reference to the ToCell
' property of the connection item
partCell = ceConnPt.RowName
' Get the Row Name of the cell that is glued
cellNme = "Connections." & partCell & ".A"
' Prepend "Connections" and then append ".A" to create the fully
' qualified cell name for the value that is to be retrieved
GluedToString = shTarget.Cells(cellNme).ResultStr("")
' Get the value out of the "A" cell in the proper Connection point
' row in the Target shape
ceInfo.Formula = Chr(34) & GluedToString & Chr(34)
' Pass that value back to the User.GluedTo Cell in the Source Shape
Else
' Otherwise...
ceInfo.Formula = Chr(34) & "<Not connected>" & Chr(34)
' Pass the string "<Not connected>" back to the User.GluedTo Cell
' in the Source Shape
End If
' End of IF Structure
End Sub
' End of Subroutine

The key to making this work seamlessly is that when the code is triggered, the code looks for the Source Shape by name, gets its Connects Collection, and looks to see if a valid glue has been established. If it has, then the appropriate row is found and the "A" cell is queried for its value. This value is then passed back from the Target Shape to the Source Shape and the Text on the Source Shape, which takes it’s value from the User.GluedTo Cell, is updated. If no valid glue is present then the default "<Not connected>" string is passed back.

"And Now For Something Completely Different…"
I just recently returned from Microsoft’s Business Applications Conference in Las Vegas, Nevada. In addition to a’ the grand information that was delivered to the attendees, the second keynote showed a Demo of the Visio and Great Plains interoperability functionality. Subsequent to that showing, the Visio booth was bedlam. The theme of the conference was "No App Is An Island" and this interoperability demo hit the nail "richt upon the heed"!!! Remember that the applications tha’ you create should not only be designed to increase your productivity within the Visio environment, but should be designed to solve the larger business challenges that you and your enterprise face every day!

Your solutions should take full advantage of Visio’s scalable architecture. Begin with a wee bit o’ customisation within the ShapeSheet environment. Modify existing shapes. Create your own shapes. Maximise what you can do within the SmartShape symbols. Then… dig in there an’ begin tae sling a wee bit o’ VBA code. It’s no’ as hard as ye micht think!!! After you have Visio really hummin’, then look at ways tae pass that intelligent information in your Visio Diagrams oot tae… sey… Excel, oor Access, oor Word!!! Imagine a full sales proposal system automated from within Visio, sending the final documents out through Word with a quick detour through Excel to generate financial analysis an’ a layo’er in Access to look up the business rules for the configuration.

Folks!!! This is verra powerfu’ stuff!!! And you have the complete toolkit to make it happen. Visio, MS Office, and the VBA built in to all of them!!!

Weel… till the next time… I bid ye mak the most o’ the tools tha’ ye ha’e an’….

"Haste ye back."

Dave "The Auld Scotsman" Edson

Dave's Hot Download
A Visio drawing with source and target shapes defined, programmed and ready to rock and roll... or highland fling... as the case may be...
CONNECT.ZIP (18Kb)

 

 
Rate this article...
Hmmm  OK  Good  Yes! Brilliant
Your a friend about this article.

Copyright © 1998-2007 DBM & others | Disclaimer | Privacy | Re-publication | Trademarks | Webmaster | Home