读取和删除菜单
**** Hidden Message ***** 您可以直接在代码中构建菜单。从{ACAD_DIR}\Sample\VBA\VBAIDEMenu\检查custom_menu.dvb。 只要知道2007处理菜单的方式非常不同。适用于2004年的代码不适用于2007年,2007年的菜单很困难。 哦,太好了......我应该编写一个适用于所有用户的程序,但现在我发现这是不可能的...... 不是不可能,只是有很多乐趣。那你想做什么,也许我们能帮上忙 我知道用Lisp代码回答VBA主题很有趣,但再次强调,knowlendge是Knolenge,不应该隐藏()。
我找到了一种轻松加载和删除菜单的方法:
首先,我将filedia系统变量设置为0,以便通过代码操作AutoCAD。
使用MENULOAD命令加载我想要的菜单,然后使用MENULOAD删除它
我恢复了filedia值,仅此而已<嗯,没有……原因是我还没有在菜单行中插入菜单下拉列表。有人知道我如何用代码做到这一点吗?
Sub Example_InsertInMenuBar()
' This example creates a new menu called TestMenu and inserts a menu item
' into it. The menu is then displayed on the menu bar.
' To remove the menu after execution of this macro, use the Customize Menu
' option from the Tools menu.
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 a menu item to the new menu
Dim newMenuItem As AcadPopupMenuItem
Dim openMacro As String
' Assign the macro string the VB equivalent of "ESC ESC _open "
openMacro = Chr(3) & Chr(3) & Chr(95) & "open" & Chr(32)
Set newMenuItem = newMenu.AddMenuItem(newMenu.count + 1, "Open", openMacro)
' Display the menu on the menu bar
newMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.count + 1)
End Sub
和删除
Sub Example_RemoveFromMenuBar()
' This example creates a new menu called TestMenu and inserts a menu item
' into it. The menu is then displayed on the menu bar, and then
' removed from the menu bar.
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 a menu item to the new menu
Dim newMenuItem As AcadPopupMenuItem
Dim openMacro As String
' Assign the macro string the VB equivalent of "ESC ESC _open "
openMacro = Chr(3) & Chr(3) & Chr(95) & "open" & Chr(32)
Set newMenuItem = newMenu.AddMenuItem(newMenu.count + 1, "Open", openMacro)
' Display the menu on the menu bar
newMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.count + 1)
GoSub QUERYMENU
' Remove the menu from the menu bar
newMenu.RemoveFromMenuBar
GoSub QUERYMENU
Exit Sub
QUERYMENU:
If newMenu.OnMenuBar Then
MsgBox "The menu called " & newMenu.name & " is on the menu bar."
Else
MsgBox "The menu called " & newMenu.name & " is not on the menu bar."
End If
Return
End Sub
是的,我知道我知道...今天下午在贝鲁的时候,我在VBA的帮助下展示了这个。但是我发现了一个更简单的方法!使用AutoLISP!就是这里:
( menucmd "P12=+MyMenuGroup。MyMenuName" )
将从指定的菜单组(MyMenugroup)加载指定的菜单(MyMenuName),该菜单组应已使用MENLOAD命令加载。在上面的示例中,菜单被添加到菜单行上的位置12之前。
因此,只需3行代码,就可以加载、指定选项和卸载菜单!
页:
[1]