The menucmd function controls the display of the menus on the menu bar, drawing area, or an image title menu.
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:
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 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 customization file submenu references.
If menu_area specifies a pull-down menu or image tile menu, action can be an asterisk ( * ). This causes the menu to be displayed; pull-down menus and image tile menus are not automatically displayed when they are called.
(menucmd "P0=POP0") ; Loads the POP0 menu into the P0 menu area (menucmd "P0=*") ; Display it
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
If your menu uses the disabling (graying-out) and marking features, you can retrieve and change the state of a menu item 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=~"
(menucmd "P2.4=") ; Enables the label (menucmd "P2.4=~") ; Disables the label
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 on a menu, you specify the menu group and name tag associated with the menu item.
(menucmd "Gacad.ID_New=~") ; Disables the label (menucmd "Gacad.ID_New=") ; Enables the label
Not only can an AutoLISP function enable and disable menu item 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.
(defun C:CTIME ( / ctim) (setq ctim (menucmd "M=$(edtime,$(getvar,date),H:MMam/pm)")) (princ (strcat "\nThe current time is " ctim )) (princ) )