haitu 发表于 2006-1-5 12:05:00

如何在CAD中自己做一个菜单

   本人在CAD的内嵌VBA环境中用窗体实现了某些功能,现在需要一个菜单和这个窗体关联,在选择菜单后调出该窗体,请问如何添加~~

songzhi 发表于 2006-1-8 20:43:00

<P>看看这个</P>
<P>Private Sub AddExtMenu()<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; On Error Resume Next<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim CurrMenuGroup As AcadMenuGroup<BR>&nbsp;&nbsp;&nbsp; Dim menuPopupItem As AcadPopupMenuItem<BR>&nbsp;&nbsp;&nbsp; Dim newMenu As AcadPopupMenu<BR>&nbsp;&nbsp;&nbsp; Dim menuSp As AcadPopupMenuItem<BR>&nbsp;&nbsp;&nbsp; Dim menuErase As AcadPopupMenu<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim strMacro As String<BR>&nbsp;&nbsp;&nbsp; Dim macro As String<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set CurrMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)<BR>&nbsp;&nbsp;&nbsp; Set newMenu = CurrMenuGroup.Menus.Add("编程(" &amp; Chr(Asc("&amp;")) &amp; "P)")<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; macro = Chr(vbKeyEscape) + Chr(vbKeyEscape) &amp; Chr(16) &amp; "-vbarun" + Chr(32) &amp; "ThisDrawing.setasInner" &amp; Chr(32)<BR>&nbsp;&nbsp;&nbsp; strMacro = "内轮廓(" &amp; Chr(Asc("&amp;")) &amp; "N)"<BR>&nbsp;&nbsp;&nbsp; Set menuPopupItem = newMenu.AddMenuItem(newMenu.count + 1, strMacro, macro)<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp; Set menuSp = newMenu.AddSeparator(newMenu.count + 1)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set menuErase = newMenu.AddSubMenu(newMenu.count + 1, "删除引线")<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '屏幕指定<BR>&nbsp;&nbsp;&nbsp; macro = Chr(vbKeyEscape) + Chr(vbKeyEscape) &amp; Chr(16) &amp; "-vbarun" + Chr(32) &amp; "ThisDrawing.EraseLeadLines" &amp; Chr(32)<BR>&nbsp;&nbsp;&nbsp; strMacro = "选择(" &amp; Chr(Asc("&amp;")) &amp; "S)"<BR>&nbsp;&nbsp;&nbsp; Set menuPopupItem = menuErase.AddMenuItem(menuErase.count + 1, strMacro, macro)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '删除所有的引入引出线<BR>&nbsp;&nbsp;&nbsp; macro = Chr(vbKeyEscape) + Chr(vbKeyEscape) &amp; Chr(16) &amp; "-vbarun" + Chr(32) &amp; "ThisDrawing.EraseAllLeadLines" &amp; Chr(32)<BR>&nbsp;&nbsp;&nbsp; strMacro = "全部(" &amp; Chr(Asc("&amp;")) &amp; "E)"<BR>&nbsp;&nbsp;&nbsp; Set menuPopupItem = menuErase.AddMenuItem(newMenu.count + 1, strMacro, macro)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set menuSp = newMenu.AddSeparator(newMenu.count + 1)<BR>&nbsp;&nbsp;&nbsp; 'AutoPRO<BR>&nbsp;&nbsp;&nbsp; macro = Chr(vbKeyEscape) + Chr(vbKeyEscape) &amp; Chr(16) &amp; "-vbarun" + Chr(32) &amp; "ThisDrawing.Programing" &amp; Chr(32)<BR>&nbsp;&nbsp;&nbsp; strMacro = "数控编程(" &amp; Chr(Asc("&amp;")) &amp; "A)"<BR>&nbsp;&nbsp;&nbsp; Set menuPopupItem = newMenu.AddMenuItem(newMenu.count + 1, strMacro, macro)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; macro = Chr(vbKeyEscape) + Chr(vbKeyEscape) &amp; Chr(16) &amp; "-vbarun" + Chr(32) &amp; "ThisDrawing.Trial" &amp; Chr(32)<BR>&nbsp;&nbsp;&nbsp; strMacro = "模拟切割(" &amp; Chr(Asc("&amp;")) &amp; "T)"<BR>&nbsp;&nbsp;&nbsp; Set menuPopupItem = newMenu.AddMenuItem(newMenu.count + 1, strMacro, macro)<BR>&nbsp;&nbsp;&nbsp; 'menuPopupItem.Enable = False<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set menuSp = newMenu.AddSeparator(newMenu.count + 1)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; macro = Chr(vbKeyEscape) + Chr(vbKeyEscape) &amp; Chr(16) &amp; "-vbarun" + Chr(32) &amp; "ThisDrawing.NC_DrawFile" &amp; Chr(32)<BR>&nbsp;&nbsp;&nbsp; strMacro = "NC-&gt;图形(" &amp; Chr(Asc("&amp;")) &amp; "D)"<BR>&nbsp;&nbsp;&nbsp; Set menuPopupItem = newMenu.AddMenuItem(newMenu.count + 1, strMacro, macro)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set menuSp = newMenu.AddSeparator(newMenu.count + 1)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; macro = Chr(vbKeyEscape) + Chr(vbKeyEscape) &amp; Chr(16) &amp; "-vbarun" + Chr(32) &amp; "ThisDrawing.About" &amp; Chr(32)<BR>&nbsp;&nbsp;&nbsp; strMacro = "关于(" &amp; Chr(Asc("&amp;")) &amp; "B)..."<BR>&nbsp;&nbsp;&nbsp; Set menuPopupItem = newMenu.AddMenuItem(newMenu.count + 1, strMacro, macro)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '显示菜单<BR>&nbsp;&nbsp;&nbsp; newMenu.InsertInMenuBar ThisDrawing.Application.MenuBar.count - 1<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '释放对象<BR>&nbsp;&nbsp;&nbsp; Set menuSp = Nothing<BR>&nbsp;&nbsp;&nbsp; Set CurrMenuGroup = Nothing<BR>&nbsp;&nbsp;&nbsp; Set newMenu = Nothing<BR>&nbsp;&nbsp;&nbsp; Set menuPopupItem = Nothing<BR>&nbsp;&nbsp;&nbsp; Set menuErase = Nothing<BR>&nbsp;&nbsp;&nbsp; <BR>End Sub<BR></P>

macula 发表于 2006-1-9 16:31:00

userform.show

haitu 发表于 2006-1-10 11:18:00

<P>多谢多谢啊~~~~</P>
页: [1]
查看完整版本: 如何在CAD中自己做一个菜单