明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1847|回复: 3

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

[复制链接]
发表于 2006-1-5 12:05:00 | 显示全部楼层 |阅读模式
   本人在CAD的内嵌VBA环境中用窗体实现了某些功能,现在需要一个菜单和这个窗体关联,在选择菜单后调出该窗体,请问如何添加~~
发表于 2006-1-8 20:43:00 | 显示全部楼层

看看这个

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

发表于 2006-1-9 16:31:00 | 显示全部楼层
userform.show
 楼主| 发表于 2006-1-10 11:18:00 | 显示全部楼层

多谢多谢啊~~~~

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 06:22 , Processed in 0.187160 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表