明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1732|回复: 2

[求助]《AutoCAD VBA & VB.NET开发基础与实例教程》 关于VBA增加菜单的问题

[复制链接]
发表于 2010-6-3 12:00:00 | 显示全部楼层 |阅读模式

P257 :代码如下,运行后报错:运行时错误,菜单组中存在弹出菜单。

当然这个错误书中也提及了 不过“因为时间所迫,没有找到合适的解决方案”。哪位高手可以帮忙看下~~谢谢

Public Sub AddMenu()

'获得当前的菜单组

Dim currMenuGroup As AcadMenuGroup

Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0) ''''这里为什么是Item(0) 啊。

'''创建菜单

Dim newMenu As AcadPopupMenu

Set newMenu = currMenuGroup.Menus.Add("MyMen" & Chr(Asc("&")) & "u")


'''''添加菜单项

Dim macro As String

marco = Chr(vbKeyEscape) + Chr(vbKeyEscape) ''''''相等与按下两次Esc

'''


''''Open 菜单项

Dim menuItem As AcadPopupMenuItem

Set menuItem = newMenu.AddMenuItem(newMenu.Count + 1, Chr(Asc("&")) & "OpenFile", macro & "_open")

menuItem.HelpString = "打开图形文件\VBA精彩实例"


''''CLose菜单项

Set menuItem = newMenu.AddMenuItem(newMenu.Count + 1, Chr(Asc("&")) & "CloseFile", macro & "_close")

menuItem.HelpString = "关闭图形文件\VBA精彩实例"


'''''分割线

Set menuItem = newMenu.AddSeparator("")


''''draw(含有子菜单)

Dim menuDraw As AcadPopupMenu

Set menuDraw = newMenu.AddSubMenu(newMenu.Count + 1, Chr(Asc("&")) & "Draw")


''''''子菜单项目 line

Dim subMenuItem As AcadPopupMenuItem

Set subMenuItem = menuDraw.AddMenuItem(menuDraw.Count + 1, Chr(Asc("&")) & "Line", macro & "_Line")


'''''''子菜单项目 Arc

Set subMenuItem = menuDraw.AddMenuItem(menuDraw.Count + 1, Chr(Asc("&")) & "Arc", macro & "_Arc")


'''''''子菜单项目 Circle

Set subMenuItem = menuDraw.AddMenuItem(menuDraw.Count + 1, Chr(Asc("&")) & "Circle", macro & "-vbarun" + Chr(32) + "ThisDrawing.DrawCircle" + Chr(32))


''''''dimension (含有子菜单)

Dim menuDim As AcadPopupMenu

Set menuDim = newMenu.AddSubMenu(newMenu.Count + 1, "Dimension" & Chr(Asc("&")) & "n")


''''''子菜单项目 dimAligned

Set subMenuItem = menuDim.AddMenuItem(menuDim.Count + 1, "DimAli" & Chr(Asc("&")) & "gned", macro & "_DimAligned")


''''''子菜单项目 dim linear

Set subMenuItem = menuDim.AddMenuItem(menuDim.Count + 1, "Dim" & Chr(Asc("&")) & "Ordinate", macro & "_DimLinear")


'''''''子菜单项目 dimOrdinate

Set subMenuItem = menuDim.AddMenuItem(menuDim.Count + 1, "Dim" & Chr(Asc("&")) & "Ordinate", macro & "_DimOrdinate")


'''''''在菜单上显示菜单

newMenu.InsertInMenuBar ThisDrawing.Application.MenuBar.Count + 1


'''查找快捷键

Dim scMenu As AcadPopupMenu

Dim element As AcadPopupMenu

Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(1)


For Each element In currMenuGroup.Menus

If element.ShortcutMenu = True Then

Set scMenu = element

Exit For

End If

Next element


''''为快捷菜单添加菜单项-测量距离()

Dim scMenuItem As AcadPopupMenuItem

Set scMenuItem = scMenu.AddMenuItem(scMenu.Count, "测量距离(&D)", macro & "_Dist")


End Sub

发表于 2010-6-9 15:55:00 | 显示全部楼层

楼主能否上传此书给明经的兄弟们一起学习学习...答案还的高手来解决...

 楼主| 发表于 2010-6-11 09:49:00 | 显示全部楼层

不好意思,不是电子版的

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

本版积分规则

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

GMT+8, 2024-11-25 22:59 , Processed in 0.158061 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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