AutoCAD VBA添加菜单

# 给cad添加自定义菜单

 

 1 Private Sub AddBar()
 2     Dim NewMenuItem As AcadPopupMenuItem
 3     Dim TheMacro As String
 4     Dim MI As Integer
 5     
 6     On Error Resume Next
 7     Dim currMenuGroup As AcadMenuGroup
 8     Set currMenuGroup = Application.MenuGroups.Item(0)
 9     'Create the new menu
10     Set NewMenu = currMenuGroup.Menus.Add("批量绘图")
11     If Err.Number Then
12         Err.Clear
13         For Each NewMenu In currMenuGroup.Menus
14             If NewMenu.Name = "批量绘图" Then Exit For
15         Next
16     End If
17     
18     'Add a menu item to the new menu
19     'Assign the macro string the VB equivalent of "ESC ESC _open "
20     'TheMacro = Chr(3) & Chr(3) & Chr(95) & "-vbarun ""GeoSection.dvb!DZPM.GeoSection""" & Chr(32)
21     TheMacro = Chr(3) & Chr(3) & Chr(95) & "-vbarun ""MainSub""" & Chr(32)
22     Set NewMenuItem = NewMenu.AddMenuItem(NewMenu.Count + 1, "批量绘图", TheMacro)
23     If Err.Number Then Err.Clear
24     'Display the menu on the menu bar
25     NewMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.Count + 1)
26     If Err.Number Then Err.Clear
27 End Sub
View Code

写几个事件驱动菜单显示

 

 1 Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
 2     If StrComp(Left$(CommandName, 3), "VBA", 1) <> 0 And UCase$(CommandName) <> "APPLOAD" Then Exit Sub
 3     If NewMenu Is Nothing Then AddBar
 4 End Sub
 5 
 6 Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
 7     If StrComp(Left$(CommandName, 3), "VBA", 1) <> 0 And UCase$(CommandName) <> "APPLOAD" Then Exit Sub
 8     If NewMenu Is Nothing Then AddBar
 9 End Sub
10 
11 Public Sub MainSub()
12     Dim frm As New UserForm1
13     Call UserForm1.Show
14 End Sub
View Code

 最终效果

 

转载于:https://www.cnblogs.com/NanShengBlogs/p/10957730.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值