3 4
If you like to put Visio commands at your fingertips, you can define commands that appear when you right-click a shape. All Visio shapes already include on their shortcut menus a number of commands for formatting and editing, and if you know how to program in the ShapeSheet, you can write your own command to do anything you want. However, with a minimum of ShapeSheet knowledge, you can add a shortcut command to do any of the actions provided by the Double-Click tab in the Behavior dialog box. In addition, this section shows you how to program a ShapeSheet function for putting any Visio command on a shape's shortcut menu.
When you want to add a command to a shape's shortcut menu, you must display the Actions section of the ShapeSheet window. For some shapes, this section already appears in the ShapeSheet window. For other shapes, you have to add it. The Actions section includes cells that define the names of commands as they appear on a shape's shortcut menu (the Menu cell) and the action to take when the command is selected (the Action cell), as Figure 25-9 shows.
Figure 25-9. This shape has four special shortcut commands that Visio added after the shape was linked to a database. These commands run add-ins that control the database link. (An ampersand in the name defines the command's keyboard shortcut.)
Follow these steps to display the Actions section:
The new Actions section doesn't do anything as is. To create a command, you have to type a label enclosed in quotation marks in the Menu cell, and then define the action to take in a formula in the Action cell. However, you can let Visio write the formula as the following section explains.
You can use the Action command, which is available only in the ShapeSheet window, to add a right-click action to a shape. The Action dialog box provides the same options as the Double-Click tab of the Behavior dialog box, as Figure 25-10 shows. The difference is that Visio creates a command on the shortcut menu instead of defining a double-click action.
Figure 25-10. Just as you can define a double-click behavior for a shape, you can add a shortcut command for a shape in the Action dialog box.
Follow these steps to add a predefined action:
For more options, you can program the action that takes place when the shortcut command is selected. Although this book isn't a programming guide, there is one particularly useful formula that you can use in the Actions section to place a Visio command on the shape's shortcut menu. For example, you can add shortcut commands for changing the zoom level or displaying the Pan & Zoom window, as Figure 25-11 shows.
Visio includes a function called DOCMD (for "do command") that causes a command to be executed. When you add a DOCMD function to a formula in the Action cell of the ShapeSheet window, you can add a Visio command to a shape's shortcut menu. The DOCMD function takes as its argument an identifier that maps to a command on a Visio menu. These identifiers are documented for programmers in the Visio Type Library, which you can display with the Object Browser in Visual Basic for Applications. For the purposes of this book, a handful of identifiers for useful commands are provided. For example, you can display the Size & Position window with the following formula, where 1670 identifies the Size & Position Window command:
=DOCMD(1670)
Figure 25-11. This shape includes four custom formulas in the Actions section of the ShapeSheet that add commands for quickly zooming in and out in a drawing.
Caution
Follow these steps to add a Visio command to a shape's shortcut menu:
=""
Table 25-5. Command Identifiers for Use with the DOCMD Function
Command | Identifier | Command | Identifier |
---|---|---|---|
View, Size & Position Window | 1670 | View, Zoom, 75% | 1034 |
View, Drawing Explorer Window | 1721 | View, Zoom, 100% | 1035 |
View, Pan & Zoom Window | 1653 | View, Zoom, 150% | 1036 |
File, Print Preview | 1490 | View, Zoom, 200% | 1037 |
View, Zoom, 50% | 1279 | View, Zoom, 400% | 1280 |