Adding Shortcut Commands to Shapes

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.)

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:

  1. Select a shape, and then choose Window, Show ShapeSheet.
  2. Scroll down in the ShapeSheet window until you see the Actions section. If you don't see it, choose Insert, Section.
  3. Select the Actions check box, and then click OK.

    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.

Adding a Predefined Action

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.

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:

  1. Display the Actions section for a shape as described in the previous procedure.
  2. If the shape already includes actions, you must insert a new row as follows: click in the last Menu or Action cell to select it. Then right-click the cell and choose Insert Row After.

  3. Click the blank Menu or Action cell, and then choose Edit, Action.
  4. In the Menu box, type the name of the command as you want it to appear on the shortcut menu.
  5. Under Action, choose the action you want the command to take, and then click OK.
  6. To test the new command, click the Close button in the ShapeSheet window to return to the drawing page. Then right-click the shape, and choose the new command.

Adding a Visio Command

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.

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


The downside of the DOCMD function is that it can get you into trouble—it executes a command without regard for other actions that are taking place in Visio. For example, you can use the DOCMD function to add the Change Spelling command to a shape's shortcut menu, but the command won't do anything, because it doesn't work outside of the context of the Spelling command. In past versions of Visio, users were actively discouraged from using this function by a lack of documentation. Still, you can safely use the DOCMD function for commands that do not require particular data to be available, such as displaying the Custom Properties window or changing zoom level.

Follow these steps to add a Visio command to a shape's shortcut menu:

  1. Display the Actions section for a shape as described in the previous procedure.
  2. If the Actions section doesn't include a blank row, select the last Menu or Action cell. Then right-click the cell and choose Insert Row After.
  3. Click the Menu cell in the row you inserted to display its formula on the formula bar at the top of the screen. The current formula looks like this:
      ="" 
  4. Click the insertion point between the two quotation marks. Type the name of the command as you want it to appear on the shortcut menu. The command name must appear between the quotation marks. Press Enter or click the Accept button (the blue check mark) to add the formula.
  5. Double-click the Action cell in the same row to edit its formula (which is currently 0).
  6. Type DOCMD followed by parentheses and a command identifier. (See Table 25-5 for a list of useful commands and their identifiers.)
  7. Press Enter or click the Accept button. The new row in the Actions section should look something like this:

  8. To test the new command, click the Close button in the ShapeSheet window to return to the drawing page. Then right-click the shape, and choose the new command.

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



Microsoft Visio Version 2002 Inside Out
Microsoft Visio Version 2002 Inside Out (Inside Out (Microsoft))
ISBN: 0735612854
EAN: 2147483647
Year: 2000
Pages: 211
Authors: Nanette Eaton

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net