night1001 发表于 2008-10-30 23:06:00

求助,期待高人献身讲解CAD中如何添加自定义菜单

<p>我想在cad菜单栏上新增一个下拉菜单,就像文件,编辑,视图一样</p><p>我用vba编了一个界面可以实现一些计算绘图等功能,就想在下拉菜单中可以把他调出来</p><p>请高手详细指点下~</p><p></p><p>网上查了下menu, menuload命令,要加载xx.mun,但是如何编辑mnu文件呢</p><p>高手能不能举个例子,做一个mnu文件,让下拉菜单下可以实现一个什么最简单的功能</p><p></p><p></p>

aicr317 发表于 2008-11-2 14:32:00

<p><font size="2">新建TXT文件,输入以下内容:</font></p><p><font size="2">***MENUGROUP=工具<br/>***POP1</font><br/><font size="2">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;</font><br/><font size="2">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;[我的二次开发]</font><br/><font size="2">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;^C^C_1</font><br/><font size="2">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;[--]</font><br/><font size="2">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;^C^C_2</font><br/><font size="2">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;[--]</font><br/><font size="2">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;[-&gt;3]</font><br/><font size="2">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;^C^C_A</font><br/><font size="2">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[--]</font><br/><font size="2">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;[&lt;-B]^C^C_B</font></p><p><font size="2"></font></p><p></p><p><br/><font size="2"></font><br/><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;保存退出,更改后缀TXT为MNU即可.</font><br/><font size="2">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;打开CAD,输入MENULOAD,把这个文件加载进去,这样,一个简单的菜单文件就构成了.其中^C^C_后面跟的是快捷命令</font></p>

hstea 发表于 2008-11-5 09:28:00

<strong>"献身"?怕怕!!</strong>

zctao1966 发表于 2008-11-14 21:39:00

aicr317发表于2008-11-2 14:32:00static/image/common/back.gif新建TXT文件,输入以下内容:***MENUGROUP=工具***POP1&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp

<p>我也这样做过了,怎么就是不行呢??</p>

dbczhaoy 发表于 2008-11-16 13:50:00

<p>直接用文本编辑软件对MNU文件进行编辑就可以了</p><p></p>

yefeiwolaile 发表于 2008-11-18 00:27:00

<p></p><p>慢慢看吧,我也好久没做了!这是我机子上的源码。</p><p>Sub AcadStartup()</p><p><br/>&nbsp;&nbsp;&nbsp; ' 该示例创建一个名为TestMenu 的新菜单,并在其中插入一个菜单项。<br/>&nbsp;&nbsp;&nbsp; ' 然后将菜单显示在菜单栏中。<br/>&nbsp;&nbsp;&nbsp; ' 在执行完该宏后如果需要将该菜单删除,可从【工具】菜单的【自定义菜单】项中删除。<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; </p><p>&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; <br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' 创建新菜单<br/>&nbsp;&nbsp;&nbsp; Dim newMenu As AcadPopupMenu</p><p>&nbsp;&nbsp;&nbsp; Set newMenu = currMenuGroup.Menus.Add("功能")<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' 添加一个菜单项到新的菜单中<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim newMenuItem1, newmenuitem2, newmenuitem3, newmenuitem4 As AcadPopupMenuItem<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp; Dim newMenuItem5, newmenuitem6 As AcadPopupMenuItem<br/>&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim openMacro1, openmacro2, openmacro3, openmacro4 As String<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim openMacro5, openmacro6, openmacro7 As String<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' 指定宏字符串,该字符串相当于VB中的 "ESC ESC _open "<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; openMacro1 = Chr(3) &amp; Chr(3) &amp; Chr(95) &amp; "-vbarun xlstocad" &amp; Chr(32)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Set newMenuItem1 = newMenu.AddMenuItem(newMenu.Count + 1, "从EXCEL导至CAD", openMacro1)<br/>&nbsp;&nbsp;&nbsp; </p><p>&nbsp;&nbsp; <br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; openmacro2 = Chr(3) &amp; Chr(3) &amp; Chr(95) &amp; "-vbarun cadtoxls" &amp; Chr(32)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Set newmenuitem2 = newMenu.AddMenuItem(newMenu.Count + 2, "从CAD导至EXCEL", openmacro2)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; openmacro3 = Chr(3) &amp; Chr(3) &amp; Chr(95) &amp; "-vbarun shanchul" &amp; Chr(32)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Set newmenuitem3 = newMenu.AddMenuItem(newMenu.Count + 3, "删除文字", openmacro3)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; openmacro4 = Chr(3) &amp; Chr(3) &amp; Chr(95) &amp; "-vbarun lcwdmdhgs" &amp; Chr(32)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Set newmenuitem4 = newMenu.AddMenuItem(newMenu.Count + 4, "另存为独门独户改水", openmacro4)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; openMacro5 = Chr(3) &amp; Chr(3) &amp; Chr(95) &amp; "-vbarun lcwxz" &amp; Chr(32)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Set newMenuItem5 = newMenu.AddMenuItem(newMenu.Count + 5, "另存为新装", openMacro5)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; openmacro6 = Chr(3) &amp; Chr(3) &amp; Chr(95) &amp; "-vbarun lcwzzlgs" &amp; Chr(32)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Set newmenuitem6 = newMenu.AddMenuItem(newMenu.Count + 6, "另存为公寓住宅楼改水", openmacro6)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; openmacro7 = Chr(3) &amp; Chr(3) &amp; Chr(95) &amp; "-vbarun lcwgsgc" &amp; Chr(32)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Set newmenuitem7 = newMenu.AddMenuItem(newMenu.Count + 7, "另存为公司工程", openmacro7)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' 显示菜单到菜单栏中</p><p><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; newMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.Count + 1)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; <br/>End Sub</p>

栗江涛 发表于 2008-11-23 04:19:00

直接做成按钮不就行了,何必搞菜单

night1001 发表于 2008-12-6 23:50:00

<p><strong><font face="Verdana">非常感谢aicr317</font></strong></p><p><strong><font face="Verdana">我要的就是像这样的文件</font></strong></p><p><strong><font face="Verdana">不过现在我还有一点不清楚,&nbsp; 我有个文件 e:\text.dvb,这个文件中有一个模块叫做mk1,模块mk1中有个 sub abc()</font></strong></p><p><strong><font face="Verdana">现在我想在点“2”时可以调用abc这个代码应该怎么写?</font></strong></p><p><strong><font face="Verdana"></font></strong></p><p><strong><font face="Verdana">我是这么写的:</font></strong></p><p><strong><font face="Verdana"></font></strong></p><p><strong><font face="Verdana">***MENUGROUP=工具<br/>***POP1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [我的二次开发]<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ^C^C_1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [--]<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ^C^C_vbarun E:\test.dvb!mk1.abc<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [--]<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [-&gt;3]<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ^C^C_A<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [--]<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ^C^C_c</font></strong></p><p><strong><font face="Verdana"></font></strong></p><p><strong><font face="Verdana">但是不能实现,不知道为什么,应该这么写“vbarun E:\test.dvb!mk1.abc”吗?</font></strong></p><p><strong><font face="Verdana">该怎么写?希望还能指教一下<br/></font></strong></p>

night1001 发表于 2008-12-7 00:10:00

感谢yefeiwolaile

<p>非常感谢<strong><font face="Verdana">yefeiwolaile,你的代码可以添加菜单,但是我还想问一下</font></strong></p><p><strong><font face="Verdana">如何给这些菜单赋予他们的职责呢,还有重要的一点能不能让这个菜单随CAD自动加载?</font></strong></p>

aicr317 发表于 2008-12-7 22:05:00

night1001发表于2008-12-7 0:10:00static/image/common/back.gif非常感谢yefeiwolaile,你的代码可以添加菜单,但是我还想问一下如何给这些菜单赋予他们的职责呢,还有重要的一点能不能让这个菜单随CAD自动加载?

<p>完全可以随CAD一起启动,你不能运行的原因是,你没有设定好你VBA中的模块和宏的名称,你把VBA发上来,我帮你改好菜单文件!</p>
页: [1] 2
查看完整版本: 求助,期待高人献身讲解CAD中如何添加自定义菜单