All menu items share the following properties:
A tag, or name tag, is a string consisting of alphanumeric and underscore (_) characters. This string uniquely identifies the menu item within a given menu. Tags identify the accelerator keys (keyboard key sequences) that correspond to the menu item.
You can read or write the value of a tag by using the TagString property.
A label is a string that defines the content and formatting of menu items.
Menu item labels can contain DIESEL string expressions that conditionally alter the labels each time they are displayed.
You can read or write the value of a label by using the Label property.
A caption is the text that the user sees displayed on the menu. This property is read-only and is derived from the Label property by removing any DIESEL string expressions.
You can read the value of a caption by using the Caption property.
A macro is a series of commands that executes specific actions when a menu item is selected. Menu macros can simply be recordings of keystrokes that accomplish a task, or they can be a complex combination of commands, AutoLISP, DIESEL, or ActiveX programming code.
You can read or write the value of a menu macro by using the Macro property.
A help string is the text string that appears in the AutoCAD status line when a user highlights a menu item for selection.
You can read or write the value of a help string by using the HelpString property.
Using the Enable property, you can enable or disable a menu item. You can also read the Enable property to determine if a menu item is currently enabled or disabled. Using this property to enable or disable a menu item overrides any setting for enabling in the DIESEL expression of the menu item.
Explore the Properties of Menu Items for an example of disabling menu items.
SeeUsing the Check property you can check or uncheck a menu item. You can also read the Check property to determine if a menu item is currently checked or unchecked. Using this property to check or uncheck a menu item overrides any setting for checking in the DIESEL expression of the menu item.
The index of a menu item specifies the position of that menu item on the menu on which it belongs. The index position of a menu always begins with position 0. For example, if the item is the first item on a menu, it returns an index position of 0. If it is the second item on a menu, it returns an index position of 1 and so on.
acMenuItem. If the item is a separator, this property returns acMenuSeparator. If the item is a heading for a submenu, this property returns acSubMenu.
You can determine the type of a menu item by using the Type property. A menu item can be one of the following types: a regular menu, a separator, or the heading for a submenu. If the item is a regular menu item, this property returnsacSubMenu, this property returns the menu that is attached as the submenu, or embedded menu. The embedded menu is returned as a PopupMenu object.
You can find the submenu by using the SubMenu property. If the menu item is of the typeacSubMenu, this property returns an error.
If the menu item is not of the typeYou can find the menu to which a menu item belongs by using the Parent property. This property returns the menu on which the menu item resides. The parent menu is returned as a PopupMenu object.
This example creates a new menu called “TestMenu” and inserts two menu items. The second menu item is then disabled using the Enable property and the menu is displayed on the menu bar.
Sub Ch6_DisableMenuItem()
Dim currMenuGroup As AcadMenuGroup
Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)
' Create the new menu
Dim newMenu As AcadPopupMenu
Set newMenu = currMenuGroup.Menus.Add("TestMenu")
' Add two menu items and a menu separator to the new menu
Dim MenuEnable As AcadPopupMenuItem
Dim MenuDisable As AcadPopupMenuItem
Dim MenuSeparator As AcadPopupMenuItem
Dim openMacro As String
' Assign the macro the VB equivalent of "ESC ESC _open "
openMacro = Chr(3) + Chr(3) + "_open "
Set MenuEnable = newMenu.AddMenuItem _
(newMenu.count + 1, "OpenEnabled", openMacro)
Set MenuSeparator = newMenu.AddSeparator("")
Set MenuDisable = newMenu.AddMenuItem _
(newMenu.count + 1, "OpenDisabled", openMacro)
' Disable the second menu item
MenuDisable.Enable = False
' Display the menu on the menu bar
newMenu.InsertInMenuBar _
(ThisDrawing.Application.menuBar.count + 1)
End Sub