I've been spending more time on Visio layout and routing in a customer project recently. Visio normally does a good job of laying out shapes and routing connectors between them, but occasionally you need to get a bit more insight into what's going on and in this post I'm going to demonstrate a few shape tools that can help.
Note - whenever I'm describing connector and routing behaviour in this post I'm talking about the Dynamic Connector
rather than any of the passive connectors (eg More Shapes / Visio Extras / Connectors
)
The layout and routing UI in Visio allows you to choose from a number of algorithms and styles and apply this to your page.
Whichever dialog you're using, you're applying a set of values at page or selection level and these values get written to the respective ShapeSheet cells. The challenge, when you're trying to marry up what you see on the drawing page and the ShapeSheet, is two fold:
- first, when you look at the ShapeSheet, unless you're editing a cell you only see the enum integer values, rather than the descriptive names
- second, there's quite a lot of round tripping to edit those values and see their effect
To address this I've put together some shapes that will read and write to the main layout and routing cells and, hopefully, make it easier to see what's happening.
The shapes are packaged into a single stencil that you can drop into Documents/My Shapes
for quick access.
The file can be downloaded from here:
* WARNING - These shapes write to cells, as well as reading from them. Please try them out on a copy of your document until you're comfortable with how this process works - use is at your own risk.
Layout and Routing Glossary
Before I get into the shapes I thought I'd establish some basic layout and routing language so we have a common understanding. The following comes from Developing Visio Solutions.
- Placeable shape A two-dimensional (2-D) shape that is set to work with routable connectors and automatic layout. If a shape is set as placeable, a routable connector can detect and avoid crossing through it. You can set a shape as placeable in the Behavior dialog box, by selecting Lay out and route around in the Placement behavior list. If you glue a routable connector, such as the dynamic connector, to a 2-D shape, Visio automatically sets the 2-D shape as placeable.
- Routable connector A one-dimensional (1-D) connector that automatically changes its path to avoid crossing through two-dimensional (2-D) placeable shapes that lie between the two shapes the connector connects. When you select a routable connector, it displays midpoints and vertices that you can drag to edit the connector's path manually.
- Plow - To plow, in Visio parlance, is to move a shape out of the way when another shape is placed on or near an existing shape
- Glue Shape behavior that causes one shape to stay connected to another, even if the shape to which it is glued moves. Gluing is a directional operation: If shape A is glued to shape B, shape B is not glued to shape A.
- Dynamic glue A type of glue behavior in which the endpoint of a connector can move from one connection point to another as the connected shapes are moved. Also called walking glue.
- Static glue A type of glue behavior in which the endpoint of a connector remains fixed to a particular connection point, no matter how the shape it is glued to moves.
Stencil shapes interaction
All of the shapes carry Shape Data that automatically read cell values on drop (in the case of the page masters) or, on setting the target shape ID (in the case of the shape level masters). This Shape Data also allows for write functionality, so any changes that you make will be written back to the respective cells.
When writing to cells, in general, things that have to do with connector routing should update immediately within the drawing and things that have to do with layout or placement will only update once a new layout call is made either in code (eg ActivePage.Layout()
) or via the UI (Design / Layout / Re-layout Page / More Layout Options...
)
Each shape also carries a Layout Shapes...
context menu item that brings up the Configure Layout dialog, but remember to set the scope (see red arrow) accordingly:
Page level
There are two shapes that focus on Page level cells:- Block and Avenue and Page Layout and Routing.
Block and Avenue
This shape is a quick visual reference of the Block
and Avenue
sizes, where Blocks (light grey above) are the areas allocated to placeable shapes and Avenues (darker grey above) are the spaces between those areas. Note that Visio uses these values when EnableGrid
= true.
Page Layout and Routing
This shape highlights the main page level cells that affect placement and routing.
- Placement cells
PlaceStyle
- the placement algorithm to applyPlaceDepth
- affects how deeply Visio reads a graph of shapes before laying out shapes
- Routing cells
RouteStyle
- sets the routing direction and style applied to connectorsLineAdjustFrom
(Separate) - specifies whether connector lines that overlap are separatedLineAdjustTo
(Overlap) - specifies whether connector lines that are separated should be overlapped
Shape level
The other two main shapes are ones that focus on shape level cells - Connector Routing (1D) and Shape Layout (2D).
Shape IDs
Since these shapes focus on a single target shape we need some way to identify it. I wanted to provide these tools as a ShapeSheet-only solution so that the stencil can be shared more easily, however, the downside of this is that you don't have any mouse events or hit testing to play with. So instead you need to know what your target shape's ID is and set this in the Shape Data.
There's a few ways you can do this:
- Use the number in the shape name - generally (but not always) the number element in a shape name is the ID.
- Use the shape name dialog - if you're running Visio in Developer mode then hit
Alt + L + N
- For 2D shapes use the
Shape ID
master included in the stencil - this is aCallout
shape that shows the target's ID (see green circle shape below) - Temporarily set an
=ID()
function in the respective shape's ShapeSheet and view it value (F5
) - the least attractive option but it does work
Now that you've got the means of identifying the target shape, I'm using the technique described in the previous post to track that shape with a dot so you can see which shape you're after.
Connector Routing
This shape exposes three cells:
ShapeRouteStyle
- generally defaults to useThePage!RouteStyle
, but offers the same set of routing styles at a local levelConFixedCode
- determines on what basis (when) the connector re-routes. Visio also firesByAlg...
values in here based on which end of the connector is connect to a target shape (or not)GlueType
- controls whether the connector uses static or dynamic glue (see GlueType docs for more information on the set of rules that affect behaviour)
Shape Layout
This final shape highlights the main cells that affect layout on per shape basis:
ShapePlaceStyle
- as perShapeRouteStyle
above, this generally defaults to useThePage!PlaceStyle
ShapeFixedCode
- this is a bit field cell (ie multiple values can be combined) and affects how shapes are placed during layout and, how connectors glue to a shape and its connection point (or their influence in this)ShapePermeableX/Y
- two cells that determine whether a connector can route directly through a this shape either horizontally (X) or vertically (Y), or, as is more standard it routes around this shapeShapePermeablePlace
- determines whether other shapes can be placed on top of this shape (ie can this shape be plowed)ShapePlowCode
- affects the plowing behaviour of this shape (ie can this shape plow other shapes)ObjType
- sets whether this shape is placeable, routable or neither
Enjoy
So I hope you find these shapes useful. I've certainly found them to be helpful in identifying what state my shapes in and what effect changes to the cells make.