参股银行 发表于 2009-10-31 22:48:00

如何用VB 实现CAD添加菜单?

<p>CAD添加菜单:menuload--选择要添加的文件。</p><p>请问用VB能实现上述的操作不?</p>

home 发表于 2009-11-3 17:25:00

<p>Sub Example_AddMenuItem()<br/>&nbsp;&nbsp;&nbsp; ' This example creates a new menu called TestMenu and inserts a menu item<br/>&nbsp;&nbsp;&nbsp; ' into it. The menu is then displayed on the menu bar.<br/>&nbsp;&nbsp;&nbsp; ' To remove the menu after execution of this macro, use the Customize Menu<br/>&nbsp;&nbsp;&nbsp; ' option from the Tools menu.<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; ' Create the new menu<br/>&nbsp;&nbsp;&nbsp; Dim newMenu As AcadPopupMenu<br/>&nbsp;&nbsp;&nbsp; Set newMenu = currMenuGroup.Menus.Add("TestMenu")<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Add a menu item to the new menu<br/>&nbsp;&nbsp;&nbsp; Dim newMenuItem As AcadPopupMenuItem<br/>&nbsp;&nbsp;&nbsp; Dim openMacro As String<br/>&nbsp;&nbsp;&nbsp; ' Assign the macro string the VB equivalent of "ESC ESC _open "<br/>&nbsp;&nbsp;&nbsp; openMacro = Chr(3) &amp; Chr(3) &amp; Chr(95) &amp; "open" &amp; Chr(32)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Set newMenuItem = newMenu.AddMenuItem(newMenu.Count + 1, "Open", openMacro)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Display the menu on the menu bar<br/>&nbsp;&nbsp;&nbsp; newMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.Count + 1)<br/>&nbsp;&nbsp;&nbsp; <br/>End Sub<br/></p><p>这里有个vba的例子,用vb应该也可以吧,没有测试</p>

xmjiacad 发表于 2009-11-9 22:17:00

<p>不知道你的问题解决了没,VB也是可以实现的:</p><p>Dim menuNames As String<br/>Dim menuCollection As AcadPopupMenus<br/>Dim menu As AcadPopupMenu<br/>&nbsp;acadapp.AcadStartup<br/>Set menuCollection = acadapp.MenuGroups.Item(0).Menus<br/>menuNames = ""<br/>For Each menu In menuCollection<br/>menuNames = menu.Name<br/>If menuNames = "KKS处理" Then<br/>On Error Resume Next<br/>menu.RemoveFromMenuBar<br/>End If<br/>Next menu<br/>' 定义当前菜单组的变量<br/>Dim currMenuGroup As AcadMenuGroup<br/>Set currMenuGroup = acadapp. _<br/>MenuGroups.Item(0)</p><p>' 创建新菜单<br/>Dim newMenu As AcadPopupMenu<br/>'---------------------------------------------------------------------------------------------<br/>Set newMenu = currMenuGroup.Menus.Add("KKS处理")</p><p>' 声明表示菜单项的变量<br/>Dim newMenuItem As AcadPopupMenuItem<br/>Dim openMacro As String<br/>openMacro = Chr(3) &amp; Chr(3) &amp; Chr(95) &amp; "open" &amp; Chr(32)<br/>' 并创建菜单项<br/>Set newMenuItem = newMenu.AddMenuItem(newMenu.Count + 1, _<br/>"填充KKS码到块属性", openMacro)&nbsp;&nbsp; '将菜单与宏对应</p><p>' 在菜单栏上显示菜单<br/>On Error Resume Next<br/>currMenuGroup.Menus.InsertMenuInMenuBar "KKS处理", ""<br/>'-----------------------------------------------------</p><p>我们要做的主要内容就是openMacro的过程编写了</p>

yznang 发表于 2009-11-16 16:47:00

<p>Public Sub CreateMenu()<br/>On Error Resume Next<br/>'用AutoCAD菜单组的第一项创建一个菜单组<br/>Dim CurMenuGroup As Object<br/>Set CurMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)<br/>'创建一个名为“CAD增强插件”的菜单项,设S为加速键<br/>Dim NewMenu As Object<br/>Set NewMenu = CurMenuGroup.Menus.Add("CAD增强插件(" + Chr(Asc("&amp;")) + "S)")<br/>'确定选择项的宏<br/>Dim FlowMacro As String<br/>'为宏分配命令<br/>'即VBA中的 ESC ESC 设计流程<br/>FlowMacro = Chr(3) &amp; Chr(3) &amp; "(vl-vbarun " &amp; Chr(34) &amp; "DefPipeSize" &amp; Chr(34) &amp; ")" &amp; Chr(13)</p><p>'添加选择项到CAD增强插件菜单项中<br/>Dim FlowMenuItem As Object<br/>Dim SepaMenuItem As Object&nbsp;&nbsp;&nbsp; '分隔符<br/>Set FlowMenuItem = NewMenu.AddMenuItem(NewMenu.Count + 1, Chr(Asc("&amp;")) + "插入页码", FlowMacro)<br/>Set SepaMenuItem = NewMenu.AddSeparator(NewMenu.Count + 1)<br/>'创建子菜单<br/>Dim SingleMenu As Object<br/>Set SingleMenu = NewMenu.AddSubMenu(NewMenu.Count + 1, "横断面修改")<br/>'将选择项添加到子菜单中<br/>Dim SubMenuItem As Object<br/>Dim SubMacro As String<br/>SubMacro = Chr(3) &amp; Chr(3) &amp; "(vl-vbarun " &amp; Chr(34) &amp; "Start_HdmBz" &amp; Chr(34) &amp; ")" &amp; Chr(13)<br/>Set SubMenuItem = SingleMenu.AddMenuItem(SingleMenu.Count + 1, "横断面高程标注 ", SubMacro)</p><p>Set SepaMenuItem = NewMenu.AddSeparator(NewMenu.Count + 1)<br/>'即VBA中的 ESC ESC 设计流程<br/>FlowMacro = Chr(3) &amp; Chr(3) &amp; "(vl-vbarun " &amp; Chr(34) &amp; "AboutUs" &amp; Chr(34) &amp; ")" &amp; Chr(13)<br/>Set FlowMenuItem = NewMenu.AddMenuItem(NewMenu.Count + 1, Chr(Asc("&amp;")) + "关于", FlowMacro)<br/>FlowMacro = Chr(3) &amp; Chr(3) &amp; "(vl-vbarun " &amp; Chr(34) &amp; "SetOption" &amp; Chr(34) &amp; ")" &amp; Chr(13)<br/>Set FlowMenuItem = NewMenu.AddMenuItem(NewMenu.Count + 1, Chr(Asc("&amp;")) + "设置", FlowMacro)</p><p><br/>'在AutoCAd菜单条上显示新创建的菜单<br/>NewMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.Count + 1)<br/>End Sub</p><p></p><p>'拷别人的,自己换用相应的方法就行了</p>

houlinbo 发表于 2010-5-26 16:07:00

怎么在前面加图标?
页: [1]
查看完整版本: 如何用VB 实现CAD添加菜单?