Example 1: Creating an Attachment Line
- Last UpdatedMar 07, 2024
- 4 minute read

For shapes that can be attached to other shapes using a control handle, such as labels and off-line instruments, it can be preferred to have an attach line showing where the item is connected. This can be achieved by going though the following steps:
-
Create the shape which is going to represent the offline instrument or label in MS Visio by using the drawing tools. If the shape is more complicated (consisting of several shapes) it should be grouped before proceeding.
-
Draw the attachment line and adjust z-order of the shapes (in most cases the attachment line should be sent to back).

-
Group the instrument or label shape and attachment line.

-
Access the Shape Sheet of the group (available on the right click menu).
-
If there is no Controls section, create a new one(Right click > Insert section). The newly created control should be named Attach.

-
Now, when the Attach control is added to the group, the attachment line should be adjusted so it starts to refer to the shape representing instrument or label (rectangle) and its end, to the position of Attach control belonging to the group. In order to do this go to the command Shape Sheet of the attachment line and do the following changes:
-
Refer beginX and beginY cells to the middle of a sub-shape representing instrument:

To refer to the instrument shape, its ID should be used. It can be found in the Special format window accessible from Format > Special in the shape context menu or from the main menu.

The ID's of the shapes in the example are as follows:
- 1 for the rectangle shape representing label or offline instrument (Sheet.1 should be used in formulas referring to the shape)
- 2 for the attachment line (Sheet.2 should be used in formulas referring to the shape)
- 3 for the whole group (Sheet.3 should be used in formulas referring to the shape)
-
Refer endX and endY cells to position of Attach control in the whole group (now the ID of the whole grouped shape is used):

-
-
After the references are set, the attachment line will follow the Attach control.
-
Now the alignment box of the shape should be adjusted to contain the instrument (or label) shape only. In order to do this, Attach control should be brought to inside the rectangle, so the attachment line is hidden. After that the Update Alignment Box command should be issued for the group.

-
In case there should be a possibility to turn on and off the attachment line, this can be achieved by the following:
-
Inserting an Actions section (in the Shape Sheet of the group) with the =SETF(GetRef(Actions.Row_1.Checked),NOT(GetVal(Actions.Row_1.Ch ecked))) action:

-
Referring the Checked property using the =IF(Sheet.3!Actions.Row_1.Checked,1,0) formula from the LinePattern cell of the Line Format section in the attachment line (the Shape Sheet of attachment line should be opened):

-
-
The attachment line can now be turned on and off by using the shape's right click menu:

-
The last thing to do is to make sure that the text of the created shape will be displayed in front. To do this please make sure that Group data is set to "" in the behavior window accessible from Shape Tab > Properties > behavior:

-
Now the shape prepared in the above way can be imported using the Import Shape Wizard as Offline Instrument or Label and used in the drawing.
Note:
The above example will allow for creating a shape with desired behavior only before Import Shape is executed on the shape. It is because of the need to group shapes to achieve attachment line functionality.