Adding Shortcut Commands to Shapes


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.

click to expand
Figure 25-9: This door allows users to reverse its left/right and in/out openings and set display options from its shortcut menu. (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.

  3. If you don’t see it, choose Insert, Section. 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.

Tip

You can add additional rows in the Actions section by right-clicking a cell and selecting Insert Row.

Adding a Predefined Action

New Feature 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:

  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 (if there is currently only one row in the section) or Insert Row After (if there is more than one row).

  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 Smart Tag to Your Shape

Visio 2003 allows users to not only add Smart Tags to their shapes, but enable the tags to trigger the same functions normally associated with shortcut menus. Smart Tags normally appear when the mouse is passed over the shape, but can be set to either appear when the shape is selected or remain permanently visible. To add a Smart Tag to a shape, follow these steps:

  1. Select the shape and choose Window, Show ShapeSheet.

  2. Select the ShapeSheet and select Insert, Section. Select the Smart Tags check box. A Smart Tag section and one Smart Tag row appear in the ShapeSheet window.

    click to expand

  3. Choose a display mode in the DisplayMode cell of the Smart Tags section for the Smart Tags row that you are working on. These are the modes: 0 indicates that the tag appears when cursor is passed over shape; 1 indicates that the tag appears when the shape is selected; and 2 indicates that the tag always remains on screen.

  4. Type a name in the TagName cell. This name will link your Smart Tag to an action in the Action section of the ShapeSheet. Choose something simple like Tag1.

  5. Display the Actions section for a shape as described in the previous procedure.

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

  7. Click the blank Menu or Action cell, and then choose Edit, Action.

  8. In the Menu box, type the name of the command as you want it to appear on the Smart Tag drop-down menu.

  9. Under Action, choose the action you want the command to take, and then click OK.

  10. In the TagName cell enter the name in the Smart Tag’s TagName cell. For example, if you entered Tag1 in the Smart Tag’s TagName cell, you would enter Tag1 here.

  11. Close the ShapeSheet window.

Now, when you click on the shape’s Smart Tag, a menu appears that displays the name just chosen. Clicking the name executes the action.

Note

One action can apply to numerous tags. For example, you can link the Color Scheme action to the color TagName. Each Smart Tag with the color TagName will have this option in its menu.

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.

click to expand
Figure 25-11: This shape includes a custom formula in the Actions section of the ShapeSheet that displays the Size & Position window.

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 Microsoft 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) 
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 an earlier 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:

    click to expand

  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 Office Visio 2003 Inside Out
Microsoft Office Visio 2003 Inside Out (Inside Out (Microsoft))
ISBN: 0735615160
EAN: 2147483647
Year: 2003
Pages: 209

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