The Menu Group Object

Once you've loaded a menu group, its corresponding MenuGroup object is added to the Menu-Groups collection. A MenuGroup object contains two collections, PopupMenus and Toolbars. All the menus within a menu group are members of the PopupMenus collection, and all the toolbars are members of the Toolbars collection. You access these two collections via the Menus and Toolbars properties of the MenuGroup object with the following syntax:

Set PopupMenusCollection = MenuGroupObject.Menus Set ToolbarsCollection = MenuGroupObject.Toolbars

Figure 16-3. Viewing the ListMenuGroups() code output

The following code sample sets a reference to the MenuGroup object representing the ACAD menu group if it's loaded into the current session. It then displays a list of each of the menus and toolbars that make up this menu group. Here I used the NameNoMnemonic property of the menus to display their names rather than the Name property because I didn't want to show all the accelerator keys and hot keys.

Public Sub ListMenusAndToolbars() Dim objMenuGroup As AcadMenuGroup Dim objPopupMenu As AcadPopupMenu Dim objToolBar As AcadToolbar Dim strMenusAndToolbars As String

On Error Resume Next

Set objMenuGroup = ThisDrawing.Application.MenuGroups.Item("ACAD")

If objMenuGroup Is Nothing Then

MsgBox "ACAD menu group is not loaded" Exit Sub

End If strMenusAndToolbars = _

"The ACAD menu group comprises the following menus: " & vbCrLf

For Each objPopupMenu In objMenuGroup.Menus strMenusAndToolbars = strMenusAndToolbars & _

objPopupMenu.NameNoMnemonic & ", "

Next strMenusAndToolbars = strMenusAndToolbars & vbCrLf & vbCrLf & _ " and the following toolbars: " & vbCrLf

For Each objToolBar In objMenuGroup.Toolbars strMenusAndToolbars = strMenusAndToolbars & objToolBar.Name & ", "


MsgBox strMenusAndToolbars End Sub

Figure 16-4 shows the result of this code. As you can see, the File, Edit, and View menus (as well as the Draw, Modify, and Dimension toolbars) belong to this group. Note that many of these menus and toolbars aren't normally visible when you use the AutoCAD interface.

Figure 16-4. Viewing the loaded menu group

Was this article helpful?

0 0

Post a comment