[VBA]关于CAD回车键重复响应自定义菜单中VBA宏命令问题的再次请教
<P>各位老大:上次我请教了这个问题,仍是不得其解,帮忙再看一下,如下是我自定义的菜单:</P><P>Sub AddExtMenu()<BR> <BR> On Error Resume Next</P>
<P> '获得当前菜单组<BR> Dim currMenuGroup As AcadMenuGroup<BR> Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)<BR> <BR> '创建新菜单<BR> Dim newMenu As AcadPopupMenu<BR> Set newMenu = currMenuGroup.Menus.Add("mynewmenu" & Chr(Asc("&")) & "P")<BR> <BR> '添加菜单项<BR> Dim macro As String<BR> macro = Chr(vbKeyEscape) + Chr(vbKeyEscape)<BR> <BR> Dim menuItemOpen As AcadPopupMenuItem<BR> <BR> '在菜单中调用宏<BR> Set menuItemOpen = newMenu.AddMenuItem(newMenu.Count + 1, Chr(Asc("&")) & "myprogram", macro & "-vbarun" + Chr(32) + "E:/other/VBA/project.dvb!Area.test" + Chr(32))</P>
<P> '在菜单栏上显示菜单<BR> newMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.Count + 1)</P>
<P> '释放对象<BR> <BR> Set currMenuGroup = Nothing<BR> Set newMenu = Nothing<BR> Set menuItemOpen = Nothing</P>
<P>End Sub</P>
<P>1、怎样修改才能在CAD中利用“回车”来重复响应,从而重复执行调用的E:/other/VBA/project.dvb!Area.test宏?</P>
<P>2、E:/other/VBA/project.dvb!Area.test宏可否改成相对路径,且仍能找到宏test?(test宏在Area模块里)</P>
<P>听说可以用LISP调用宏,可是我不知如何使用,找便了明经也没有合适的例子。可否赐教!谢谢。</P> <DIV>你可以参照以下代码编码编写:</DIV>
<DIV>在LISP中编写如下代码:</DIV>
<DIV>(defun c:aa()</DIV>
<DIV> (command "-vbarun" "AddGxPnt")</DIV>
<DIV>)</DIV>
<DIV> </DIV>
<DIV>你可以在AutoCad2000doc.lsp中加入自动加载VBA程序和上述LISP程序的代码,这样你进入CAD中直接输入aa 命令即可运行,回车也能重复执行</DIV> <P>我在acad2004doc.lsp文件里加入了:</P>
<P>(vl-vbaload (findfile "E:/other/VBA/Project.dvb")) <BR>(defun c:Project() <BR> (setvar "cmdecho" 0) <BR>; (vl-vbarun "AddExtMenu") <BR>(princ) <BR>) </P>
<P>(defun s::STARTUP()<BR> (command "_-vbarun" "AddExtMenu")<BR>)<BR></P>
<P>发现只有“defun s::STARTUP()”句中二楼所述的“aa”改为“STARTUP”才能自动加载并运行,但是回车还不能能重复执行,怎么回事??</P>
<P>另外第二个问题还不明白?<BR></P> 把Project.dvb复制到support文件夹,代码改为:
(defun C:Project()
(setvar "cmdecho"0)
(command "-vbarun""project.dvb!Area.test")
(setvar "cmdecho"1)
(princ)
)
页:
[1]