菜单重载问题请教
菜单程序运行两遍的时候出现错误提示“无效的过程调用和参数”,有没有办法实现不管菜单程序运行多少遍都不出错? 有呀,程序改一下,把你的程序贴出来呀。我这几天刚解决了这个问题 Dim TestMenu As AcadPopupMenu<BR>Set TestMenu = currMenuGroup.Menus.Add("软件")<BR>'为菜单项声明变量,测试用10个<BR>Dim newMenuItem(0 To 19) As AcadPopupMenuItem<BR>Dim PopMenuMacro(0 To 19) As String'赋值宏字符串并创建菜单项<BR>PopMenuMacro(0) = Chr(3) + Chr(3) + Chr(95) + "Excel_To_Map" + Chr(32)<BR>
<BR>Set newMenuItem(0) = TestMenu.AddMenuItem(TestMenu.Count + 1, "导入", PopMenuMacro(0))<BR><BR>' 在菜单条上显示菜单<BR>currMenuGroup.Menus.InsertMenuInMenuBar "软件", ""<BR>ThisDrawing.SendCommand "fileopen " & "futu.dwg" + vbCrLf<BR>ZoomAll
Exit Sub<BR>End Sub 不好意思,你的是VBA自动生成菜单,我还不太懂.我现在会CAD的菜单文件加载方法.也就是自己做一个*.MNU文件.自动加载并运行.
回复
Public Sub test()Dim myMenuName As String<BR> myMenuName = "软件"
'--------------------------------------------------------<BR> Dim currMenuGroups As AcadMenuGroups<BR> Set currMenuGroups = ThisDrawing.Application.MenuGroups<BR> Dim currMenuGroup As AcadMenuGroup<BR> <BR> Dim i As Integer<BR> Dim strMenuGrpName As String<BR> <BR> For i = 0 To currMenuGroups.Count - 1<BR> Set currMenuGroup = currMenuGroups.Item(i)<BR> strMenuGrpName = currMenuGroup.Name<BR> MsgBox strMenuGrpName<BR> If StrComp(strMenuGrpName, "ACAD", vbTextCompare) = 0 Then<BR> Dim popMenus As AcadPopupMenus<BR> Set popMenus = currMenuGroup.Menus<BR> Dim popMenu As AcadPopupMenu<BR> <BR> Dim bExist As Boolean<BR> bExist = False<BR> <BR> Dim strMenuName As String<BR> <BR> Dim j As Integer<BR> For j = 0 To popMenus.Count - 1<BR> <BR> Set popMenu = popMenus.Item(j)<BR> strMenuName = popMenu.Name<BR> <BR> If StrComp(strMenuName, myMenuName, vbTextCompare) = 0 Then<BR>' If popMenu.OnMenuBar = True Then<BR>' popMenus.RemoveMenuFromMenuBar (myMenuName)<BR>' End If<BR> bExist = True<BR> Exit For<BR> End If<BR> Next<BR> <BR> If bExist = False Then<BR> ' Create the new menu<BR> Dim newMenu As AcadPopupMenu<BR> Set newMenu = currMenuGroup.Menus.Add(myMenuName)<BR> <BR> ' Add a menu item to the new menu<BR> Dim newMenuItem As AcadPopupMenuItem<BR> Dim openMacro As String<BR> ' Assign the macro string the VB equivalent of "ESC ESC _open "<BR> openMacro = Chr(3) & Chr(3) & Chr(95) & "open" & Chr(32)<BR> <BR> Set newMenuItem = newMenu.AddMenuItem(newMenu.Count + 1, "Open", openMacro)<BR> <BR> ' Display the menu on the menu bar<BR> popMenus.InsertMenuInMenuBar myMenuName, ""<BR> <BR> End If<BR> <BR> Exit For<BR> <BR> End If<BR> Next
End Sub
现在不会有你说的问题了,但是有些疑问,
popMenus.RemoveMenuFromMenuBar (myMenuName)不能彻底移除一个popMenu.
回复
修改了一下.Public Sub test()
Dim myMenuName As String<BR> myMenuName = "软件"
'--------------------------------------------------------<BR> Dim currMenuGroups As AcadMenuGroups<BR> Set currMenuGroups = ThisDrawing.Application.MenuGroups<BR> Dim currMenuGroup As AcadMenuGroup<BR> <BR> Dim i As Integer<BR> Dim strMenuGrpName As String<BR> <BR> For i = 0 To currMenuGroups.Count - 1<BR> Set currMenuGroup = currMenuGroups.Item(i)<BR> strMenuGrpName = currMenuGroup.Name<BR> MsgBox strMenuGrpName<BR> If StrComp(strMenuGrpName, "ACAD", vbTextCompare) = 0 Then<BR> Dim popMenus As AcadPopupMenus<BR> Set popMenus = currMenuGroup.Menus<BR> Dim popMenu As AcadPopupMenu<BR> <BR> Dim bExist As Boolean<BR> bExist = False<BR> <BR> Dim strMenuName As String<BR> <BR> Dim j As Integer<BR> For j = 0 To popMenus.Count - 1<BR> <BR> Set popMenu = popMenus.Item(j)<BR> strMenuName = popMenu.Name<BR> <BR> If StrComp(strMenuName, myMenuName, vbTextCompare) = 0 Then<BR>' Call clearPopupMenuItem(popMenu)<BR> If popMenu.OnMenuBar = False Then<BR> popMenus.InsertMenuInMenuBar myMenuName, ""<BR> End If<BR> bExist = True<BR> Exit For<BR> End If<BR> Next<BR> <BR> If bExist = False Then<BR> ' Create the new menu<BR> Dim newMenu As AcadPopupMenu<BR> Set newMenu = currMenuGroup.Menus.Add(myMenuName)<BR> <BR> ' Add a menu item to the new menu<BR> Dim newMenuItem As AcadPopupMenuItem<BR> Dim openMacro As String<BR> ' Assign the macro string the VB equivalent of "ESC ESC _open "<BR> openMacro = Chr(3) & Chr(3) & Chr(95) & "open" & Chr(32)<BR> <BR> Set newMenuItem = newMenu.AddMenuItem(newMenu.Count + 1, "Open", openMacro)<BR> <BR> ' Display the menu on the menu bar<BR> popMenus.InsertMenuInMenuBar myMenuName, ""<BR> <BR> End If<BR> <BR> Exit For<BR> <BR> End If<BR> Next
End Sub 多谢斑竹,献花一朵
为什么不能彻底移除一个popMenu?
本帖最后由 作者 于 2004-10-1 16:01:15 编辑为什么不能彻底移除一个popMenu?
移除之后,下次循环还能找到?为什么?应该怎么做?
[询问]如何删除popupmenu
<b><BR></b>再次请问如何彻底移除一个popMenu?popMenus.RemoveMenuFromMenuBar (myMenuName)
移除之后,下次执行程序循环AcadPopupMenus还能找到myMenuName,为什么?应该怎么做真正地删除? 在AUtoCad的一次运行过程中无法移除,但是重新打开会消失
页:
[1]