飞鸟 发表于 2010-5-18 17:21:00

怎么在cad里创建一个菜单项,单击弹出窗体

<p>怎么在cad里创建一个菜单项,单击弹出已经设计好的窗体啊,请高手指教,最好有个代码示例</p>

forowhl 发表于 2010-5-18 23:35:00

<p>下面的代码是“开口汇料0430.dvb”文件里面的添加菜单项,运行“huiliao”这个函数</p><p>Private Sub AcadDocument_EndCommand(ByVal CommandName As String)<br/>&nbsp; Dim i As Integer<br/>&nbsp; Dim ts As String, sta As String, sta1 As String, VBAProjectPath As String<br/>&nbsp; <br/>&nbsp; <br/>&nbsp; On Error GoTo errhand</p><p>' MsgBox CommandName<br/>If CommandName = "VBALOAD" Or CommandName = "VBAMAN" Or CommandName = "APPLOAD" Or CommandName = "COMMANDLINE" Then&nbsp;&nbsp; '启动时菜单的生成<br/>&nbsp;&nbsp;&nbsp;&nbsp; ' 该示例创建一个名为开口汇料新菜单,并在其中插入一个菜单项。<br/>&nbsp;&nbsp;&nbsp; ' 然后将菜单显示在菜单栏中。<br/>&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; <br/>&nbsp;&nbsp;&nbsp; Dim newMenu As AcadPopupMenu<br/>&nbsp;&nbsp;&nbsp; Set newMenu = currMenuGroup.Menus.Add("开口汇料")<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; sta = ""<br/>&nbsp;&nbsp;&nbsp; VBAProjectPath = ""<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; For i = 1 To Application.VBE.VBProjects.Count<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ts = Application.VBE.VBProjects(i).FileName<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sta = InStrRev(ts, "\", , vbTextCompare)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sta1 = Right(ts, Len(ts) - sta)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If sta1 = "开口汇料0430.dvb" Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'VBAProjectPath = ts 'Left(ts, sta)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit For<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; Next<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; For i = 1 To Len(ts)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Mid(ts, i, 1) = "\" Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VBAProjectPath = VBAProjectPath &amp; "/"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VBAProjectPath = VBAProjectPath &amp; Mid(ts, i, 1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Next<br/>&nbsp;&nbsp;&nbsp; <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 newMenuItem As AcadPopupMenuItem<br/>&nbsp;&nbsp;&nbsp; Dim openMacro As String<br/>&nbsp;&nbsp;&nbsp; ' 指定宏字符串,该字符串相当于VB中的 "ESC ESC _open "<br/>&nbsp;&nbsp;&nbsp; openMacro = "-vbarun " &amp; VBAProjectPath &amp; "!ThisDrawing.huiliao "<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Set newMenuItem = newMenu.AddMenuItem(newMenu.Count + 1, "开始汇料", openMacro)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' 显示菜单到菜单栏中<br/>&nbsp;&nbsp;&nbsp; newMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.Count + 1)</p><p></p><p><br/>End If</p><p></p><p>errhand:<br/>If Err.Number = 0 Or Err.Number = -2147024809 Then</p><p>&nbsp; Else<br/>&nbsp; <br/>&nbsp;&nbsp;&nbsp; MsgBox Err.Description &amp; Err.Number<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Err.Clear<br/>&nbsp;&nbsp;&nbsp; <br/>End If</p><p>End Sub</p>

hellommmm 发表于 2010-5-21 22:28:00

学习

obaby1221 发表于 2011-1-21 09:02:37

学习~         

hongfuxian 发表于 2011-3-27 18:05:22

怎么运行呀

藏羚 发表于 2012-12-21 23:16:33

用手工添加,请参见我写的:将VLX文件或者Lisp文件添加为CAD菜单的方法详解

页: [1]
查看完整版本: 怎么在cad里创建一个菜单项,单击弹出窗体