Design-Drawing Home  
Drawing Program
ISSN 1441-5585

Search...

Home
Articles
Software Catalog
Book Store
About
Advertising
Newsletter

 

 

Layering Visio Drawings

David J Parker

A CAD user describes his experiences in learning how to use layers in Visio. David Parker describes how to use layers to control diagram display.  As a bonus, he includes two in-line VBA scripts that allow Visio to mimic layer features found in CAD software: insert layer name in drawing, and group layer controls.

Coming from a CAD background, there were two areas of using Visio where I had to grasp new ways of working: Layers and Shared Drawings.

The Purpose of Layers
A layer is a method of grouping similar items together (layers are known as levels in some CAD systems). Layers let you simultaneously change the visibility, printability, line color, and line width of all shapes located on the same layer. Layers are a good way to organize drawings, because the same drawing can be used for different disciplines, each using their own set of layers, and each being able to see the others. For example, the lighting engineer can see the ventilation outlets in a reflected ceiling plan, but they can also be printed and viewed separately. Moreover, the line colour of items on a layer can be changed to identify them more easily.

Visio has the ability to have a shape assigned to more than one layer -- a concept unknown in the world of CAD. This can be useful, for example, when your diagram has a Partition layer, and you want some shapes on the To Be Removed layer and some on the New Build layer.

Remember that shapes can belong to no layer at all, so your Visio diagram can have no layers at all -- again, a concept unknown to the CAD user. It is not a good idea for drawings of any complexity to have no layers.

The Layer Properties dialog box is Visio's primary interface to the properties of the layers.

Visio's Layer Properties dialog box reports the number of shapes assigned to each layer
Visio's Layer Properties dialog box reports the number of shapes assigned to each layer

Take a look at the # column: this gives you the count of shapes on the layer. In the figure, you see a 2 in each case. The Square, Triangle and Circle shapes are on layers One, Two, and Three respectively, while the Sigma shape is on all three layers (it gets counted on each layer). Moreover, if the shapes were groups (several shapes grouped together), then its sub-groups are counted, too. For this reason, do not rely on this count to be an inventory count.

The Visio Layer Properties dialog controls the color of shapes on each layer
The Visio Layer Properties dialog controls the color of shapes on each layer

The Layer Properties dialog box can be used to change the color of shapes. The figure above demonstrates how an assigned layer color changes the line and text color, but removes fill color. Fortunately, this is not permanent; clear the layer color to return the shapes' original settings. Notice that the Sigma shape has not changed appearance, even though it is assigned to layer Three, amongst others. This is because when Visio has a choice, so it does nothing. If, however, all its assigned layers had the same color, then Sigma would change, too.

The Drawing Explorer in Visio 2000 offers a way of changing the visibility of a layer easily, and lets you set the active layer. The active layer, or layers, is applied to all subsequently drawn shapes.

Figure 3: The Drawing Explorer is new in Visio 2000, and displays layer information for each shape
The Drawing Explorer is new in Visio 2000, and displays layer information for each shape

The Legend Shape
When I work with a drawing in CAD, I place a piece of text with the name of each layer, assigned to that layer, discretely along the side of the drawing. In this way, I could see which levels were plotted or not. Controlling the plotting of layers is as important as the name of the file, because the entire plotted appearance of the drawing can be different for the same file. I have created a Visio SmartShape to perform the same function, called the Legend shape. I'll explain here how to create it for yourself.

The Legend shape is a useful indicator of the status for each layer, essential information if you need to repeat a print of a drawing at different times. The Legend shape shows the visibility and printability of each layer, and is not assigned to any layer (for this reason, it appears under the Shapes branch of the Drawing Explorer, and not under the Layers branch).

I have assigned a double-click event to the Legend shape, which allows text to be created automatically. To create this shape, just draw a rectangle, then show its ShapeSheet (from the Visio menu bar, select Window>Show Shapesheet). Scroll down to the Events section, and select the EventDblClick cell. In this cell, type (or copy'n paste) the following in-line VBA code (note that this is all one line):

=RUNADDON("strL=""Layers on this page:"":
For i = 1 to ActivePage.Layers.Count:strL= strL & vbcrlf & ActivePage.Layers(i).Name & vbtab & ActivePage.Layers(i).CellsC(4).ResultIU & vbtab & ActivePage.Layers(i).CellsC(5).ResultIU:Next i:ActiveWindow.Selection(1).Text=strL")

Back in the drawing, double-click the shape to refresh the text. You can format the text, and use tabs to make it look pretty. 

Grouping Layers
Currently, whether you use the Layer Properties dialog or the Drawing Explorer, you change layer settings individually. A feature missing from Visio is group layer management, something found in some CAD systems. By this I mean several layers can be given a group name. Recalling the name changes the settings of all layers in the group. This would allow me, for example, to switch between an Electrical engineer's view and a mechanical engineer's view of the same drawing.

In the following example I have created two groups of layers, A and B. Group layer A contains layers One and Two, and group layer B contains layers One and Three. The sequence shows the effect of switching off group A (step 2), then switching on group B (step 3), and finally switching off group B (step 4). The Legend shape shows the status of the layers at each step.

Grouping layers lets you control several layers at once
Grouping layers lets you control several layers at once

The Group Layers Switch shape In practice, I find it easier to turn off all layers before turning on selected layers of a particular group. To automate this task, I created two shapes with some in-line VBA code that turn a group of layers on or off simultaneously. The in-line VBA code for both shapes is identical, except for one number to be changed. Like the Legend shape, just draw a rectangle, then show its ShapeSheet, and add the following code to the EventDblClick cell in the Events section. Again, this must be typed as a single line:

=RUNADDON("intM=1:
aryL=split(ActiveWindow.Selection(1).Text,"";""):
intL=UBound(aryL):For i = 1 to intL:
ActivePage.Layers(aryL(i)).CellsC(4).Formula=intM:
ActivePage.Layers(aryL(i)).CellsC(5).Formula=intM:Next i")

This statement turns off the layers. To turn on layers, change intM=0 to intM=1 . The more adventurous amongst you could make this value read from a custom property on the shape, rather than have two different shapes.

Okay, so how does this work? Firstly, there is no error checking, so follow my instructions. All you have to do is type in a layer group description, then type each layer name you want to turn on/off preceded by a semi-colon. Each layer name must be type perfectly, or else you will get an error. The code assumes that there is a semi-colon separated list in the shapes text. It loops through each of them, ignoring the first item because it is the group description, then sets the layer visibility and printability to the 1 or 0, depending on what is the value of intM

So long…
I hope you have found this discussion of layers in Visio useful, and that some of you are brave enough to try the examples. In the next issue I will write about inserting and referencing CAD drawings and other Visio drawings into Visio drawings.

David J Parker

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

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