Design-Drawing Home  

ISSN 1441-5585

Search...

Home
Articles
Software Catalog
Messages & Chat
Book Store
Software Store
Professional Services
About
Advertising

Subscribe

 

Pearls from the auld Scotsman
Few people know Visio software and communicate their knowledge as well as Dave Edson. In this regular column Dave dispenses pearls of wisdom in his own inimitable style.

Wired Wi' Automation' in Visio

David A Edson

I want to take a wee bot o’ time to expand upon a couple o’ concepts that I have introduced in the past: Intelligent Connections and Programatically Manipulable Text.

With that I’d also like to add to the mix creating your own Event Sinks. ‘Tis a’weys best tae show how this is put tae use in the real world, and to that end we’ll look at this thru the practical application of a Wiring Diagram. Chris Roth, a brilliant wee laddie at Visio, created the sample wiring diagramme that is the core of this month’s column. Chris is an artist as well as an engineer and his brilliant drawings truly show it.

A’richt… let’s get started shall we?

If you’ve ever looked at wiring diagrams you know that they can be an absolute jumble of wires criss-crossing from component to component, often requiring you to trace the wire path with your finger just to ascertain where the wire "A" that began on Chip "1", Pin "8" ends up. Is wire "A" going to Pin "11" or Pin "13" on Chip "2"… or was that Chip "6"? Visually it can be a wee bit o’ a nightmare to suss it all oot!

Well here is where a wee bit o’ VBA and intelligent Visio Shapes can make working with these kinds of diagrams much easier. Because of the confusing nature of these diagrams, wires are often labeled at each end with the Chip and Pin designator for the connection at the other end. A given wire would have two labels; the label at the start references the component and pin of the termination, and the label end references the component and pin of the origin. When a designer of the wiring system moves the wire from pin to pin, or from component to component, he or she needs the labels to update automatically to reflect these changes.

To begin understandin’ how a’ this works, we shall first take a look at a "Chip" component in the diagram. If you have not already downloaded the sample drawing file, this wauld be a brilliant time tae de sae, aye? The "Chip" component is basically just a group shape consisting of a rectangle, several lines, several text items and a connection point at the end of each line representing a "Pin" on the "Chip". The Group has a UserDefinedCell which holds the colour of the FillForeground in the Rectangle which makes up the general block of the shape. Note that each ConnectionPoint on the group Shape has been designated with a Name which corresponds to the Sub-Shape Text item at its side.

Now let’s take a look at the "Wire" Shape. This shape is also a grouped shape consisting of a Sub-Shape with three line segments and two additional Sub-Shapes, each a Text-Block Shape. The overall Group Shape is a 1-D shape with several UserDefinedCells. These cells hold the values for the EndText, the BeginningText, the EndColour, the BeginningColour, the LocalShowFlag, and the ShowWire items. For more information on creatin’ yer ain 1-D Connector shapes, I refer you to the Developing Visio Solutions Text that ships with Visio in both hard-copy and electronic format.

If you look at the drawing that Chris created, you will see a series o’ tasks laid out for you to experiment with. The first of these is to toggle the visibility of all of the wire paths in the entire document. This is done with an Actions Menu item on the Page.. Look at the Page’s ShapeSheet. In the Actions Section you will find an item that states "Show Complete Wire Paths". The action that is taken is to toggle the state of the "User.ShowAllWires" cell from TRUE to FALSE and back again. This is done with a rather slick Boolean statement: =SETF("User.ShowAllWires",NOT(User.ShowAllWires)). Each "Wire" shape contains a "User.ShowWire" cell whose formula is: =NOT(OR(ThePage!User.ShowAllWires,User.LocalShowFlag)). This evaluates to either TRUE or FALSE depending on the state of the Page’s "User.ShowAllWires" cell and the individual "Wire" "User.LocalShowFlag" cell. If the individual "Wire" shape is set to be seen and the more Global Page’s "ShowAllWires" is set to do not show, it will still be seen, but if te local version is set to don’t show, the more global will take control and make it invisible. This is actually triggered in the "Wire" shape’s "NoShow" cells for each individual line segment in the Sub-Shape.

The second of these tasks is to toggle the visibility of the individual "Wire" shape. This is wrapped up in te functionality I just described above so I will not belabour the point, but note that he trigger for this is contained in the Action Section of the individual "Wire" shape as well.

The third of these tasks is to take an end of a given "Wire" shape and to disconnect and reconnect it to various differing terminals on varying "Chip" shapes. Note that when a "Wire" is disconnected from a "Pin" on a "Chip", the label at the OTHER end goes blank. When it is reconnected, it reflects the status of the new "Pin" that it has been connected to. This is truly the heart of this demonstration and of this article. (remember my 3 bits o’ functionality; Intelligent Connections, Programatically Manipulable Text, and Creating your own Event Sinks ?) A’richt… here is whar we roll uup oor sleeves an’ get intae a wee bit o’ code. We first need to create a new Class Module in our VBA project to handle the events that we are interested in:

'By Dim-ming using WithEvents, we get a Page object
'that comes with a whole bunch of events (in the VBA
'procedure drop-down list). Now we can put code in the
'ConnectionsAdded and ConnectionsDeleted procedures and
'modify our connectors as appropriate.

Public WithEvents ConnectorsPage As Visio.Page
Private Sub ConnectorsPage_ConnectionsAdded(ByVal Connects As Visio.IVConnects)

'This subroutine reacts to changes in the connections
'collection for the page.
'
'When a wire connector is attached, the "destination labels"
'that specify what the other end is attached to need to change.
'By analyzing the connect object passed into this sub, the
'name of the connection point connected to can be determined,
'and stuffed into a user cell in the connector shape.

Dim cnnct As Visio.Connect
Dim shpConnector As Visio.Shape, shpBox As Visio.Shape
Dim sDestLabel As String

'Get the last connection in the collection.
'(Technically, a connects collection is passed
'into this sub, but there's usually only one
'connects object in this collection)

Set cnnct = Connects.Item(Connects.Count)

'Get the shapes involved in the connection:

Set shpConnector = cnnct.FromSheet
Set shpBox = cnnct.ToSheet

'Bail if shpConnector isn't our special "Wire" connector,
'or doesn't even come from a master in the first place:

If shpConnector.Master Is Nothing Then Exit Sub
If shpConnector.Master.Name <> "Wire" Then Exit Sub

'Get the name of the connection point connected to,
'by stripping "Connections." off the left side, and
'".X" off the right side. If the connection point
'is not named, and has the generic form "Connections.X1"
'then the stripped name will be blank, which is good
'in this case.

sDestLabel = Mid(cnnct.ToCell.Name, 13, Len(cnnct.ToCell.Name) - 14)

'Note: the logic below looks backward. This is because
'the "destination label" reflects information pertinent
'to the other end of the connector. So when we attach the
'Begin point of the connector, we are getting information
'that will be displayed at the End point of the connector.

If cnnct.FromCell.Name = "BeginX" Then

'Set the "destination text"

shpConnector.Cells("User.EndText").Formula = QT & sDestLabel & QT

'Match the color for the text to that of the shape
'that is being connected to.

shpConnector.Cells("User.EndColor").Formula = shpBox.NameID & "!User.Color"
Else

'Set the "destination text"

shpConnector.Cells("User.BegText").Formula = QT & sDestLabel & QT

'Match the color for the text to that of the shape
'that is being connected to.

shpConnector.Cells("User.BegColor").Formula = shpBox.NameID & "!User.Color"
End If
End Sub
Private Sub ConnectorsPage_ConnectionsDeleted(ByVal Connects As Visio.IVConnects)

'When a connection is deleted, the text for that
'end of the connector needs to be deleted.

Dim cnnct As Visio.Connect
Dim shpConnector As Visio.Shape

'Get the last connection in the collection.
'Assume that this is the one we care about?

Set cnnct = Connects.Item(Connects.Count)

'Get the shapes involved in the connection:

Set shpConnector = cnnct.FromSheet

'Bail if shpConnector isn't our special "Wire" connector,
'or doesn't even come from a master in the first place:

If shpConnector.Master Is Nothing Then Exit Sub
If shpConnector.Master.Name <> "Wire" Then Exit Sub

'Now that an end point has been unglued, there shouldn't
'be any "destination label", since the end of the wire isn't
'going anywhere of interest. So...
'
'Clear the "destination text"

If cnnct.FromCell.Name = "BeginX" Then
shpConnector.Cells("User.EndText").Formula = QT & QT
Else
shpConnector.Cells("User.BegText").Formula = QT & QT
End If
End Sub

You might be askin’ yourselves what the QT variable is… Weel we define it in our global settings as follows:

'Quote character
Public Const QT$ = """"

This constant keeps us from having to knock together EXACTLY the right number of double quote marks to push a blank string to the text in the cell of the Sub-Shape of the "Wire" shape.

A’richt… there is only just a wee bit more business to take care of and the whole thing comes together…

Dim cPM As New C_PageModel

We’re gang to declare cPM as a new instantiation of our C_PageModel class

Then when we initialise the Drawing, we perform the instantiation of the Class

Sub InitializeDrawing()
Set cPM.ConnectorsPage = Visio.ActivePage
MsgBox "Drawing initialized. Have at it!!!"
End Sub

Note that when we enter Design Mode in Visio, we do not want all these events firing every time we play about with the drawing so we thrash the instantiation by settin’ it to Nothing (A VBA Keyword meanin’ remove it from memory and free all pointers set by its use).

Private Sub Document_DesignModeEntered(ByVal doc As Visio.IVDocument)
Set cPM = Nothing
End Sub

When we enter Run Mode in Visio we want to re-initialise the drawing and instantiate the class again.

Private Sub Document_RunModeEntered(ByVal doc As Visio.IVDocument
Call InitializeDrawing
End Sub

So wha’ is gang on here… ??????

When a "Wire" shape’s beginning or end point is moved in any manner, it looks to see what it is connected to at its other end… it looks at the name of the ConnectionPoint and the colour of the block and then sets the text for the "Wire" sub-Shape Text Block to the proper text and colour. If it is left hanging, it sets a blank string and nothing is displayed on that end.

Simple, clean and elegant, is it no’??? Brilliant!!!!!!

The final task is simply to turn on or off the notes for the demonstration drawing. This is also done thruu the Actions section of the Page. Note the action is simply changing the visibility status of the layers that the Notes Shapes exist upon.

Weel thar ye ha’e it folk!!!! Wiring diagrammes are a very common type of Visio Drawing and through a wee bit of work they can become far more user friendly, and much, much easier to read and work with. This, then, is truly the power of Visio drawings… friendly, intelligent drawings that are much more than static lines on paper. They can convey information, clarify intent, isolate information that is the focus of current interest and provide robust data to be used across the entire Digital Nervous System and te Enterprise.

Again, I hope tae greet an’ shake hands wi’ lots o’ ye as we progress thruu the spring an’ the mony important conferences that are oot thar!!!

As a’weys… Slainte an’… Haste ye bak!!!!

Dave "The Auld Scotsman" Edson

Dave's Hot Download
A Visio drawing with the shape defined, programmed and ready to rock and roll... or highland fling... as the case may be...
wiring-diagram.zip

 

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

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