![]() |
![]() ![]() |
Pearls from the auld Scotsman
|
Wired Wi' Automation' in VisioI 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 Id also like to add to the mix creating your own Event Sinks. Tis aweys best tae show how this is put tae use in the real world, and to that end well 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 months column. Chris is an artist as well as an engineer and his brilliant drawings truly show it. Aricht lets get started shall we? If youve 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 lets 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 Pages 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 Pages "User.ShowAllWires" cell and the individual "Wire" "User.LocalShowFlag" cell. If the individual "Wire" shape is set to be seen and the more Global Pages "ShowAllWires" is set to do not show, it will still be seen, but if te local version is set to dont show, the more global will take control and make it invisible. This is actually triggered in the "Wire" shapes "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 ?) Aricht 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:
You might be askin yourselves what the QT variable is Weel we define it in our global settings as follows:
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. Aricht there is only just a wee bit more business to take care of and the whole thing comes together
Were 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
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).
When we enter Run Mode in Visio we want to re-initialise the drawing and instantiate the class again.
So wha is gang on here ?????? When a "Wire" shapes 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 hae 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 aweys Slainte an Haste ye bak!!!! Dave "The Auld Scotsman" Edson
|
|
|
Copyright © 1998-2001 DBM & others | Disclaimer | Privacy | Re-publication | Trademarks | Webmaster | Home |