zwd0077 发表于 2006-1-18 11:15:00

[VBA]关于CAD回车键重复响应自定义菜单中VBA宏命令问题的再次请教

<P>各位老大:上次我请教了这个问题,仍是不得其解,帮忙再看一下,如下是我自定义的菜单:</P>
<P>Sub AddExtMenu()<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; On Error Resume Next</P>
<P>&nbsp;&nbsp;&nbsp; '获得当前菜单组<BR>&nbsp;&nbsp;&nbsp; Dim currMenuGroup As AcadMenuGroup<BR>&nbsp;&nbsp;&nbsp; Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '创建新菜单<BR>&nbsp;&nbsp;&nbsp; Dim newMenu As AcadPopupMenu<BR>&nbsp;&nbsp;&nbsp; Set newMenu = currMenuGroup.Menus.Add("mynewmenu" &amp; Chr(Asc("&amp;")) &amp; "P")<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '添加菜单项<BR>&nbsp;&nbsp;&nbsp; Dim macro As String<BR>&nbsp;&nbsp;&nbsp; macro = Chr(vbKeyEscape) + Chr(vbKeyEscape)<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim menuItemOpen As AcadPopupMenuItem<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '在菜单中调用宏<BR>&nbsp;&nbsp;&nbsp; Set menuItemOpen = newMenu.AddMenuItem(newMenu.Count + 1, Chr(Asc("&amp;")) &amp; "myprogram", macro &amp; "-vbarun" + Chr(32) + "E:/other/VBA/project.dvb!Area.test" + Chr(32))</P>
<P>&nbsp;&nbsp;&nbsp; '在菜单栏上显示菜单<BR>&nbsp;&nbsp;&nbsp; newMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.Count + 1)</P>
<P>&nbsp;&nbsp;&nbsp; '释放对象<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set currMenuGroup = Nothing<BR>&nbsp;&nbsp;&nbsp; Set newMenu = Nothing<BR>&nbsp;&nbsp;&nbsp; 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>

zhuxuhong 发表于 2006-1-18 14:14:00

<DIV>你可以参照以下代码编码编写:</DIV>
<DIV>在LISP中编写如下代码:</DIV>
<DIV>(defun c:aa()</DIV>
<DIV>&nbsp;&nbsp; (command "-vbarun" "AddGxPnt")</DIV>
<DIV>)</DIV>
<DIV>&nbsp;</DIV>
<DIV>你可以在AutoCad2000doc.lsp中加入自动加载VBA程序和上述LISP程序的代码,这样你进入CAD中直接输入aa 命令即可运行,回车也能重复执行</DIV>

zwd0077 发表于 2006-1-19 12:23:00

<P>我在acad2004doc.lsp文件里加入了:</P>
<P>(vl-vbaload (findfile "E:/other/VBA/Project.dvb")) <BR>(defun c:Project() <BR>&nbsp;&nbsp;&nbsp; (setvar "cmdecho" 0) <BR>; (vl-vbarun "AddExtMenu") <BR>(princ) <BR>) </P>
<P>(defun s::STARTUP()<BR>&nbsp; (command "_-vbarun" "AddExtMenu")<BR>)<BR></P>
<P>发现只有“defun s::STARTUP()”句中二楼所述的“aa”改为“STARTUP”才能自动加载并运行,但是回车还不能能重复执行,怎么回事??</P>
<P>另外第二个问题还不明白?<BR></P>

wuzhm21 发表于 2013-1-18 11:39:50

把Project.dvb复制到support文件夹,代码改为:
(defun C:Project()
(setvar "cmdecho"0)
(command "-vbarun""project.dvb!Area.test")
(setvar "cmdecho"1)
(princ)
)
页: [1]
查看完整版本: [VBA]关于CAD回车键重复响应自定义菜单中VBA宏命令问题的再次请教