Creating Routable and Other 1-D Connectors

If you are designing solutions for connected diagrams, you must decide whether your users will use the connector tools built into Microsoft® Visio® to connect your shapes or to design your own connectors.

The Connector tool, Connect Shapes command (Shape menu), and Dynamic Connector shape create routable connectors between placeable shapes. A routable connector is a 1-D shape that draws a path around other shapes rather than crossing over them on the drawing page. A placeable shape is a shape (usually 2-D) that works with the routable connector. Whether shapes are placeable and routable in a drawing determines how Visio reacts when changes occur, such as when shapes are added, deleted, resized, or repositioned. In response to such changes, Visio automatically repositions shapes that are placeable and reroutes shapes that are routable.

Routable connectors can save users time when they revise complex connected diagrams. In some cases, however, you might want a connector with more predictable behavior—that is, one that does not automatically reroute. For example, if your drawing type requires connecting lines that always form a 90-degree angle or that connect shapes with a curved connector, you can create your own 1-D connector that is not routable.

In this section...

Creating Routable Connectors

Creating Other 1-D Connectors

Creating Routable Connectors

You can create a routable connector from any 1-D line by setting its ObjType cell in the Miscellaneous section to 2.

The value specified in the ObjType cell controls whether objects are placeable or routable in diagrams when users lay out shapes using the Lay Out Shapes command (Shape menu).

The following table provides related values for the ObjType cell.

Values for a shape's ObjType cell

Value

Meaning

0 (or &H0)

Default. Visio decides whether the shape is placeable or routable based on the drawing context.

1 (or &H1)

Shape is placeable.

2 (or &H2)

Shape is routable. Must be a 1-D shape.

4 (or &H4)

The shape is not placeable, not routable.

8 (or &H8)

Group contains placeable/routable shapes. (Reserved for Visio use.)

When you create a new 2-D shape, by default Visio sets its ObjType to No Formula, which evaluates to zero (0), meaning that Visio determines whether the shape can be placeable depending on its context. For example, if you draw a simple rectangle, the value of its ObjType cell is 0 by default. If you then use the Connect Shapes command or the Connector tool to connect the rectangle to another shape, Visio decides that the rectangle can be placeable, and sets the rectangle's ObjType cell to 1 (placeable).

Note Using the ShapeSheet®, you can also create a placeable 1-D shape, which can be beneficial when the shape is not a connector and will be used in a drawing with automatic layout. Setting a 2-D shape to routable, however, has no effect on its behavior.

If you are creating shapes that you do not want to work with routable connectors, set the ObjType cell to 4. Connectors can glue to connection points on the shape, but in a diagram that contains placeable and routable connectors, the nonplaceable shape is ignored—that is, routing lines behave as if the shape does not exist.

To control the path taken by a routable connector, you set its behavior*,* which corresponds to the value of the ShapeRouteStyle cell in the Shape Layout section. By default, the value of this cell is No Formula, which evaluates to 0, meaning the connector uses the behavior set for the page.

Controlling the layout of connectors

The Lay Out Shapes command (Shape menu) and the Layout and Routing tab in the Page Setup dialog box (click Page Setup on the File menu) provide numerous choices of behavior you can specify for selected shapes or for the page by combining different connector styles with different directions. You can also specify behavior for a shape or the page by setting ShapeSheet cells:

  • For example, setting a connector's ShapeRouteStyle cell to 7 creates a routable connector that always routes as if it's contained in a tree diagram in top-to-bottom orientation. (This is equivalent to choosing Flowchart/Tree for Style and Top to Bottom for Direction in the Lay Out Shapes dialog box under Placement.)
  • To define this behavior as the page default, set the RouteStyle cell to 7 in the page's Page Layout section. (This is equivalent to choosing Tree for Style and Top to Bottom for Direction on the Layout and Routing tab in the Page Setup dialog box).

For details about other settings for the ShapeRouteStyle and RouteStyle cells, search for those cells in the Microsoft Visio Developer Reference (on the Help menu, click Developer Reference).

When you create a template for a diagram that uses routable connectors and placeable shapes, you can customize the default values that Visio uses to route and place shapes. By specifying values with the Lay Out Shapes command (Shape menu), you define the default values for the page. Users can edit shapes on the page to override the page settings; however, when users create or add placeable shapes, by default, the settings for the page are used.

For details about creating diagrams that use routable connectors and placeable shapes, search for "layout" in the Microsoft Visio Help (on the Help menu, click Microsoft Visio Help).

TOP

Creating Other 1-D Connectors

When your solution calls for a connector with behavior that you can control programmatically, you can create one that does not automatically route. You can control how a connector extends from its begin point to its end point with formulas.

Creating an angled connector: an example

The following figure shows an angled connector with two right-angle bends. The custom formulas for this connector are included in this section as a demonstration of the type of formulas you need to control 1-D shapes. You can find other 1-D connectors in the Connectors stencil (on the File menu, point to Stencils, point to Visio Extras, and then click Connectors).

The four different ways an angled connector can bend when a user moves it.

The four ways an angled connector can bend when a user moves it.

  1. BeginY <= EndY
  1. BeginX > EndX
  1. BeginX <= EndX
  1. BeginY > EndY
  1. The connector always bends 0.25 in. (vertically) from the begin point.

With its two bends in the middle, the angled connector has two vertices that require custom formulas. To calculate the coordinates of the first vertex after the begin point, remember that its x-coordinate is the same as that of the begin point. The y-coordinate is 0.25 in. if the shape is drawn from the bottom up. If it is drawn from the top down, its y-coordinate is calculated as:

The x-coordinate for the next vertex is the same as the x-coordinate for the last LineTo row, which specifies the shape's end point and so is always Width or zero (0). Its y-coordinate is the same as the preceding vertex.

To create an angled connector

  1. Select the Line tool and draw a straight 1-D line from left to right.
  1. On the Window menu, click Show ShapeSheet.
  1. Enter the following formulas in the Shape Transform section:
  • Width = GUARD(ABS(EndX � BeginX))
  • Height = GUARD(ABS(EndY � BeginY))
  • Angle = GUARD(0 deg.)
  1. On the Insert menu, click Section, and then select User-Defined Cells.
  1. In the User-Defined Cells section, enter a name for the cell, such as yOffset, and then enter 0.25 in. in the Value cell.
  1. Select the last row in the Geometry section, and then click Row After on the Insert menu. Repeat to add a total of two rows.
  1. In the Geometry section, enter the formulas shown in the following table.

Row

X

Y

MoveTo

= IF(BeginX <= EndX,0,Width)

= IF(BeginY <= EndY,0,Height)

LineTo

= Geometry1.X1

= IF(BeginY <= EndY, User.yOffset,
    Height � User.yOffset)

LineTo

= Geometry1.X4

= Geometry1.Y2

LineTo

= IF(BeginX <= EndX,Width,0)

= IF(BeginY <= EndY,Height,0)

  1. In the Protection section, set the LockHeight cell and LockVtxEdit cell to 1.
  1. Drag the begin point or end point of the connector on the drawing page to see the angle and the offset.

If you want to allow users to change the position of the bend in the angled connector, you can add a control handle by linking User.yOffset to a control handle, and then locking the handle's x-position so that it moves only in the y direction.

Creating a height-based 1-D shape

Some shapes, such as the 1-D pipe-and-valve shape in the following figure, can stretch between two points to connect other shapes. You can create this type of 1-D shape as a single shape with multiple geometry components that have different resizing behaviors. In a 1-D shape, the endpoints control the shape's width. In the pipe-and-valve shape, when a user drags an endpoint, only the line component stretches. When a user drags a top or bottom handle, only the valve component resizes, and it does so in a way that maintains its aspect ratio.

A pipe-and-valve shape with default formulas versus height-based formulas

A pipe-and-valve shape with default formulas versus height-based formulas

  1. Pipe
  1. Valve
  1. Using default formulas, the valve shape becomes distorted when stretched in either direction.
  1. Using height-based formulas, only the pipe increases in length when the valve shape is stretched horizontally.
  1. Using height-based formulas, the valve grows proportionately when stretched vertically.

To make the valve shape stretch and shrink the way it should, you use a height-based formula to define the width of the valve component in terms of the shape's height. To create this connector as a single shape, draw two line segments at either end of a valve shape, point to Operations on the Shape menu, and then click Combine.

To maintain the valve's proportions when the shape is resized, define the x-coordinates of the valve's vertices in relation to the center and height of the shape, as shown in the following figure. Doing so also serves to keep the valve centered in the width-height box. This approach requires that you set formulas in the X cell of the Geometry section.

Height-based formula for a 1-D shape with multiple geometry components

Height-based formula for a 1-D shape with multiple geometry components

  1. Width * 0.5 - Height * 1
  1. Width * 0.5
  1. Width * 0.5 + Height * 1
  1. Height
  1. Width

To create this shape in a way that ensures your Geometry rows match the figures and tables shown here

  1. Select the Line tool and draw a straight line from left to right to form the left segment of the pipe.
  1. Use the Line tool to draw the valve, starting at point 1 as shown in the preceding figure.
  1. Use the Line tool to draw the right segment of the pipe from left to right. Then draw the left segment of the pipe from left to right.
  1. Press and hold the SHIFT key while you select the shapes in this order: valve, left line, right line.
  1. On the Shape menu, point to Operations, and then click Combine.
  1. On the Format menu, click Behavior.
  1. On the Behavior tab, click Line (1-dimensional), and then click OK.

To control the valve portion of the shape, open the ShapeSheet window for the combined shape and enter the formulas shown below in the Geometry1 section.

Custom formulas in pipe-and-valve shape's Geometry1 section

Row

X

Y

MoveTo

= Width * 0.5 � Height * 1

= Height * 1

LineTo

= Geometry1.X1

= Height * 0

LineTo

= Width * 0.5 + Height * 1

= Height * 1

LineTo

= Geometry1.X3

= Height * 0

LineTo

= Geometry1.X1

= Geometry1.Y1

To control the point where the left pipe segment meets the valve (vertex 6 in the preceding figure), enter the following formula:

To control the point where the right pipe segment meets the valve (vertex 7 in the preceding figure), enter the following formula:

Tip When you draw 1-D shapes such as the pipe-and-valve shape, you often draw several shapes and then either group or combine them. Using the Combine command results in a more efficient shape. If a user doesn't need to subselect component shapes, you don't need to group them, which adds a group sheet. However, you need to make sure that the endpoints of the resulting 1-D shape are in the right place.

Visio always places the begin point on the left end of a 1-D shape and the end point on the right. If you draw a shape from top to bottom and then convert it to 1-D, the endpoints might not be where you want them. So draw the component parts from left to right.

You shouldn't add any custom formulas to the component shapes before you combine them, because the Combine command removes them anyway.