乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 63|回复: 4

[编程交流] 使用VBA创建命令

[复制链接]

34

主题

105

帖子

91

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
224
发表于 2022-7-6 17:05:09 | 显示全部楼层 |阅读模式
你好
 
可以用autocad创建命令吗?
 
我正在创建用于插入标准块的下拉菜单。我确实喜欢工具选项板,但我们有数百个标准块,这些块永远不会改变,因此创建自定义菜单似乎是最好的解决方案。
 
我在帮助中找到了如何创建菜单,但没有找到实际的命令?
 
非常感谢您的帮助。
 
col公司
回复

使用道具 举报

5

主题

35

帖子

38

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-6 17:24:36 | 显示全部楼层

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

 
我用这种方式,并为每个块单独的文件。
回复

使用道具 举报

1

主题

56

帖子

80

银币

初来乍到

Rank: 1

铜币
1
发表于 2022-7-6 17:48:08 | 显示全部楼层
 
下面是一些VBA样板代码。它创建了几个菜单,并附加了一个VBA宏,在选择菜单项时调用该宏。
 
您可能只希望创建一个“Insert”:键入子例程,然后只传递不同的参数
 
  1. Sub Main()
  2.    Dim retMenu As AcadPopupMenu
  3.    Dim retMenuItem As AcadPopupMenuItem
  4.    Const MainMenuName As String = "My&Menu" ' add an Ampersand in front of letter to make it a Hotkey
  5.    Const SubMenuName As String = "My&SubMenu"
  6.    ' either add new, or return existing main menu Item
  7.    Set retMenu = AddMainMenu(MainMenuName) '' add (or GET) main menu item
  8.    ' add some sub menu item to our main menu
  9.    For I% = 1 To 4
  10.      Set retMenuItem = AddMainMenuItem(retMenu, SubMenuName & Str$(I%), "TestSub")
  11.    Next '
  12. End Sub
  13. Private Function AddMainMenu(strMenuName As String) As AcadPopupMenu
  14.    ' adds a main menu to acad menus, or returns an existing menu with the same name
  15.    Dim currMenuGroup As AcadMenuGroup
  16.    Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item("ACAD")
  17.    For I = 0 To currMenuGroup.Menus.Count - 1
  18.        If currMenuGroup.Menus(I).Name = strMenuName Then
  19.            Set AddMainMenu = currMenuGroup.Menus(I)
  20.            Exit Function
  21.        End If
  22.    Next
  23.    ' if we're still here, we didnt find the menu, so we'll add one
  24.    Set AddMainMenu = currMenuGroup.Menus.Add(strMenuName)
  25.     ' Display the menu on the menu bar
  26.    AddMainMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.Count + 1)
  27. End Function
  28. Private Function AddMainMenuItem(objMenu As AcadPopupMenu, strMenuItem As String, strMacroName As String) As AcadPopupMenuItem
  29.    ' adds a sub menu item to the passed menu object
  30.    ' the "strMenuIte" param is the name of ther menu, per VB xconvention, embed an ampersand "&"
  31.    ' before the letter you want to be a hotkey
  32.    ' The "strMacroName" is the name of the Subroutine you want called when the menu is selected
  33.    Dim openMacro As String
  34.    openMacro = "-VBARUN " & strMacroName & " " ' add a space to enmnu item to emulate the ENTER key]'
  35.    Set AddMainMenuItem = objMenu.AddMenuItem(objMenu.Count + 1, strMenuItem, openMacro)
  36. End Function
  37. Sub TestSub()
  38.    ' name of routine to call when menu item is selected
  39.    MsgBox "your menu was just selected"
  40. End Sub
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 17:58:16 | 显示全部楼层
你可以创建自己的菜单和使用幻灯片,这就像工具选项板,但你编写代码,一个很好的例子是弹出的填充图案,你可以从图片或名称中选择
 
Serach在这里提出的“通过工具栏插入块”的问题与您在示例图片中提出的问题相同。
回复

使用道具 举报

34

主题

105

帖子

91

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
224
发表于 2022-7-6 18:18:39 | 显示全部楼层
谢谢大家,我已经考虑了一下,我不打算制作10个左右的菜单/子菜单,也不可能根据我们当时使用的铝系统加载和卸载菜单,我想我会设置1个宏来插入所有块,暂停以供用户输入块名和旋转,然后在选项中设置支持路径。
 
谢谢大家的帮助
 
col。
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 19:10 , Processed in 0.313002 second(s), 62 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表