Controlling Menus
 
 
 

The menucmd function controls the display of the graphics window menus. It displays, modifies, or queries one of the submenus of the current menu, and accepts a string argument that specifies the submenu and the action to perform on that submenu.

The menucmd function takes a string argument that consists of two fields, separated by an equal sign, in the following form:

"menu_area=action"

This syntax can load a submenu into a specified menu area, or perform an action on a menu item or a currently loaded menu area. The menu_area field specifies which part of the menu is to receive the action. This field can specify a menu area, such as P0 (for the shortcut menu) or S (for the screen menu), or a specific menu item. The action field specifies the action to perform on the menu area or menu item, or a submenu to load into the menu area. The menu areas that can receive an action are the same as those used in menu file submenu references.

Every menu area has a currently loaded submenu. By default, the first submenu following a menu section label is loaded into that menu area.

If menu_area specifies a pull-down menu or image tile menu, action can be an asterisk (*). This causes the menu to display (pull-down menus and image tile menus are not automatically displayed when they are called). In Windows, only the P0 (cursor) menu and image tile menus are displayed with the asterisk.

NoteDo not include the dollar sign that introduces the similar instructions in a menu file in the string argument. Also, do not include the asterisks that precede submenu labels in the menu file in the action field of the string argument.

The following menucmd function call causes the **OSNAP screen submenu defined in the current menu file to be displayed (assuming the screen menu is currently enabled).

(menucmd "S=OSNAP") 

In Windows, you can reference the menu group. This can be useful if there are multiple menus loaded that contain the same submenu name. The following code displays the **OSNAP screen submenu in the ACAD menu group.

(menucmd "S=ACAD.OSNAP") 

The menucmd function can load submenus into the BUTTONS and AUX menu areas. You might want your digitizer buttons to function differently depending on whether Tablet mode is on or off. You can have two submenus defined in the ***BUTTONS1 section, **DIG-BUTTONS and **TAB-BUTTONS, and switch between them with the following code.

(menucmd "B1=DIG-BUTTONS")  Enables the DIG-BUTTONS submenu
(menucmd "B1=TAB-BUTTONS")  Enables the TAB-BUTTONS submenu

The following code loads the ***POP0 menu into the P0 (cursor) menu area and displays it.

(menucmd "P0=POP0")		 Loads
the ***POP0 menu into the P0 menu area
(menucmd "P0=*")											 Displays
it

If you are sure the correct menu is loaded into a particular menu area, you do not need to load it specifically each time you want to display it.

The following call displays the pull-down menu currently loaded in the P1 (first pull-down menu) location.

(menucmd "P1=*")

Using "P1=*" without previously loading the menu can result in unexpected behavior. Although you can load virtually any menu at a pull-down or shortcut menu location, it is best to use only menus specifically designed for that menu area. For example, if you have a submenu called **MORESTUFF, you can load it at the P1 location with the following code:

(menucmd "P1=MORESTUFF")	Loads the **MORESTUFF menu in the
P1 menu location
(menucmd "P1=*")			Displays
it 

This menu remains in this location until you replace it by loading another menu, as in the following:

(menucmd "P1=POP1")

If your menu uses the disabling (graying-out) and marking features, you can retrieve and change the state of a menu label with the menucmd function. The following call retrieves the current state of the fourth label in the pull-down menu P2.

(menucmd "P2.4=#?")		 If
disabled returns   "P2.4=~" 

These function calls enable and disable that same label:

(menucmd "P2.4=")		 Enables
the label
(menucmd "P2.4=~")		Disables
the label

You can also place and remove marks to the left of menu labels.

The previously described method of menu item handling works relatively well with a single static menu. However, it becomes unreliable when menu item locations change when you load multiple partial menu files. You can make use of the menu-group and name-tag features to keep track of menu items. Instead of specifying a menu item by its location in the menu file, you specify the menu group and name tag associated with the menu item.

When you use the menu group to enable, disable, and mark menu labels, you must precede the group name with a G, as shown in the following examples.

(menucmd "Gacad.ID_New=~")  Disables the
label
(menucmd "Gacad.ID_New=")   Enables the
label

Not only can an AutoLISP function enable and disable menu labels, it can also modify the text displayed in the label by placing a DIESEL string expression in the label. Because DIESEL accepts only strings as input, you can pass information to the DIESEL expression through a USERS1-5 system variable that has been set to a value returned by your function.

You can also use the menucmd function to evaluate DIESEL string expressions within an AutoLISP function. The following routine returns the current time:

(defun C:CTIME ( / ctim)
  (setq ctim 
	(menucmd "M=$(edtime,$(getvar,date),H:MMam/pm)"))
  (princ (strcat "\nThe current time is " ctim ))
  (princ)
)

For information on the use of DIESEL expressions with AutoLISP and a catalog of DIESEL functions, see the Customization Guide. Refer also to the Customization Guide for further information on menus.