怎么在cad里创建一个菜单项,单击弹出窗体
<p>怎么在cad里创建一个菜单项,单击弹出已经设计好的窗体啊,请高手指教,最好有个代码示例</p> <p>下面的代码是“开口汇料0430.dvb”文件里面的添加菜单项,运行“huiliao”这个函数</p><p>Private Sub AcadDocument_EndCommand(ByVal CommandName As String)<br/> Dim i As Integer<br/> Dim ts As String, sta As String, sta1 As String, VBAProjectPath As String<br/> <br/> <br/> On Error GoTo errhand</p><p>' MsgBox CommandName<br/>If CommandName = "VBALOAD" Or CommandName = "VBAMAN" Or CommandName = "APPLOAD" Or CommandName = "COMMANDLINE" Then '启动时菜单的生成<br/> ' 该示例创建一个名为开口汇料新菜单,并在其中插入一个菜单项。<br/> ' 然后将菜单显示在菜单栏中。<br/> ' 在执行完该宏后如果需要将该菜单删除,可从【工具】菜单的【自定义菜单】项中删除。<br/> Dim currMenuGroup As AcadMenuGroup<br/> Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)<br/> <br/> ' 创建新菜单<br/> <br/> Dim newMenu As AcadPopupMenu<br/> Set newMenu = currMenuGroup.Menus.Add("开口汇料")<br/> <br/> sta = ""<br/> VBAProjectPath = ""<br/> <br/> For i = 1 To Application.VBE.VBProjects.Count<br/> ts = Application.VBE.VBProjects(i).FileName<br/> sta = InStrRev(ts, "\", , vbTextCompare)<br/> sta1 = Right(ts, Len(ts) - sta)<br/> If sta1 = "开口汇料0430.dvb" Then<br/> 'VBAProjectPath = ts 'Left(ts, sta)<br/> Exit For<br/> End If<br/> Next<br/> <br/> <br/> For i = 1 To Len(ts)<br/> If Mid(ts, i, 1) = "\" Then<br/> VBAProjectPath = VBAProjectPath & "/"<br/> <br/> Else<br/> <br/> VBAProjectPath = VBAProjectPath & Mid(ts, i, 1)<br/> <br/> End If<br/> <br/> Next<br/> <br/> <br/> <br/> <br/> <br/> ' 添加一个菜单项到新的菜单中<br/> Dim newMenuItem As AcadPopupMenuItem<br/> Dim openMacro As String<br/> ' 指定宏字符串,该字符串相当于VB中的 "ESC ESC _open "<br/> openMacro = "-vbarun " & VBAProjectPath & "!ThisDrawing.huiliao "<br/> <br/> Set newMenuItem = newMenu.AddMenuItem(newMenu.Count + 1, "开始汇料", openMacro)<br/> <br/> ' 显示菜单到菜单栏中<br/> 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> Else<br/> <br/> MsgBox Err.Description & Err.Number<br/> <br/> Err.Clear<br/> <br/>End If</p><p>End Sub</p> 学习 学习~ 怎么运行呀 用手工添加,请参见我写的:将VLX文件或者Lisp文件添加为CAD菜单的方法详解
页:
[1]