comcu 发表于 2022-7-6 17:05:09

使用VBA创建命令

你好
 
可以用autocad创建命令吗?
 
我正在创建用于插入标准块的下拉菜单。我确实喜欢工具选项板,但我们有数百个标准块,这些块永远不会改变,因此创建自定义菜单似乎是最好的解决方案。
 
我在帮助中找到了如何创建菜单,但没有找到实际的命令?
 
非常感谢您的帮助。
 
col公司

matthewrussell 发表于 2022-7-6 17:24:36


 
如果您试图将按钮链接到用于加载您创建的特定块的lisp文件,请使用此选项。
 
^C^C(加载“插入块”);插入detcall块
 
基本上,(加载“插入块”)是加载lisp例程。然后,第二部分是lisp中的实际命令,该命令将运行要插入的块的代码。
 
你在用lisp吗?以及您使用的autocad版本。我为我一直使用的某些块制作了特殊菜单,并发现lisp是最简单的方法。因为您可以复制和粘贴每个代码,只需更改命令行和它正在搜索的块。
 
我已附上我用于我的代码(autocad 09)
 
;---DETAIL BUBBLE---
(defun c:insert-detbub-block (/ layerset)
(setq layerset (getvar "clayer"))
(setvar "clayer" "35")
(setq scaleset(/ 1 (getvar "cannoscalevalue")))
(setvar "ATTDIA" 0)
(setq ins-pt (getpoint "\nSelect Insertion Point: <0,0>"))
(if (= nil ins-pt) (setq ins-pt (list 805 553)) )
(command "-insert" "detail bubble" ins-pt scaleset scaleset "0")
(command "explode" (entlast))
(setvar "ATTDIA" 1)
(setvar "clayer" layerset)
(princ)
) ;defun
 
我用这种方式,并为每个块单独的文件。

rocheey 发表于 2022-7-6 17:48:08

 
下面是一些VBA样板代码。它创建了几个菜单,并附加了一个VBA宏,在选择菜单项时调用该宏。
 
您可能只希望创建一个“Insert”:键入子例程,然后只传递不同的参数
 

Sub Main()
   Dim retMenu As AcadPopupMenu
   Dim retMenuItem As AcadPopupMenuItem

   Const MainMenuName As String = "My&Menu" ' add an Ampersand in front of letter to make it a Hotkey
   Const SubMenuName As String = "My&SubMenu"


   ' either add new, or return existing main menu Item
   Set retMenu = AddMainMenu(MainMenuName) '' add (or GET) main menu item

   ' add some sub menu item to our main menu

   For I% = 1 To 4
   Set retMenuItem = AddMainMenuItem(retMenu, SubMenuName & Str$(I%), "TestSub")
   Next '

End Sub

Private Function AddMainMenu(strMenuName As String) As AcadPopupMenu
   ' adds a main menu to acad menus, or returns an existing menu with the same name

   Dim currMenuGroup As AcadMenuGroup

   Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item("ACAD")
   For I = 0 To currMenuGroup.Menus.Count - 1
       If currMenuGroup.Menus(I).Name = strMenuName Then
         Set AddMainMenu = currMenuGroup.Menus(I)
         Exit Function
       End If
   Next


   ' if we're still here, we didnt find the menu, so we'll add one
   Set AddMainMenu = currMenuGroup.Menus.Add(strMenuName)
    ' Display the menu on the menu bar
   AddMainMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.Count + 1)

End Function

Private Function AddMainMenuItem(objMenu As AcadPopupMenu, strMenuItem As String, strMacroName As String) As AcadPopupMenuItem
   ' adds a sub menu item to the passed menu object
   ' the "strMenuIte" param is the name of ther menu, per VB xconvention, embed an ampersand "&"
   ' before the letter you want to be a hotkey
   ' The "strMacroName" is the name of the Subroutine you want called when the menu is selected

   Dim openMacro As String
   openMacro = "-VBARUN " & strMacroName & " " ' add a space to enmnu item to emulate the ENTER key]'
   Set AddMainMenuItem = objMenu.AddMenuItem(objMenu.Count + 1, strMenuItem, openMacro)
End Function

Sub TestSub()
   ' name of routine to call when menu item is selected
   MsgBox "your menu was just selected"
End Sub



BIGAL 发表于 2022-7-6 17:58:16

你可以创建自己的菜单和使用幻灯片,这就像工具选项板,但你编写代码,一个很好的例子是弹出的填充图案,你可以从图片或名称中选择
 
Serach在这里提出的“通过工具栏插入块”的问题与您在示例图片中提出的问题相同。

comcu 发表于 2022-7-6 18:18:39

谢谢大家,我已经考虑了一下,我不打算制作10个左右的菜单/子菜单,也不可能根据我们当时使用的铝系统加载和卸载菜单,我想我会设置1个宏来插入所有块,暂停以供用户输入块名和旋转,然后在选项中设置支持路径。
 
谢谢大家的帮助
 
col。
页: [1]
查看完整版本: 使用VBA创建命令