CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2021 开发者帮助

AddToolbarButton 方法 (ActiveX)

2024-5-18 18:32| 发布者: admin| 查看: 165| 评论: 0|原作者: admin|来自: AutoCAD

AddToolbarButton 方法 (ActiveX)

将工具栏项添加到工具栏的指定位置。

支持的平台:仅限 Windows

签名

VBA:

RetVal = object.AddToolbarButton(Index, Name, HelpString, Macro [, FlyoutButton])
对象

类型:工具栏

此方法应用到的对象。

指数

访问:仅输入

类型:变体

工具栏中要添加项的索引位置。

索引必须是整数或字符串。如果指定了整数,则索引必须介于 0 和 N-1 之间,其中 N 是工具栏中的对象数。新项目将紧接在指定的索引位置之前添加。

名字

访问:仅输入

类型:字符串

标识工具栏按钮的字符串。字符串必须包含字母数字字符,除短划线 (-) 或下划线 (_) 外,没有标点符号。当光标放在工具栏按钮上时,此字符串将显示为工具提示。

帮助字符串

访问:仅输入

类型:字符串

按钮的 AutoCAD 状态行中显示的字符串。

宏观

访问:仅输入

类型:字符串

与此项关联的宏的名称。

弹出按钮

访问:仅输入;自选

类型:变体

一个 Boolean 变量,说明新按钮是否为弹出按钮。如果按钮是浮出控件按钮,则此参数必须设置为 。如果该按钮不是浮出控件按钮,则可以将此参数设置为或忽略此参数,并将返回新对象。TrueFalseToolbarItem

  • True:该按钮是浮出控件按钮。
  • False:该按钮不是浮出控件按钮。

返回值 (RetVal)

类型:ToolbarItem

新创建的工具栏项。

言论

只有当工具栏可见时,才能添加或删除工具栏按钮。

例子

VBA:

Sub Example_AddToolbarButton()
    ' This example creates a new toolbar called TestToolbar and inserts a
    ' toolbar button into it. The toolbar is then displayed.
    ' To remove the toolbar after execution of this macro, use the Customize Menu
    ' option from the Tools menu.
    
    Dim currMenuGroup As acadMenuGroup
    Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)
    
    ' Create the new toolbar
    Dim newToolBar As AcadToolbar
    Set newToolBar = currMenuGroup.Toolbars.Add("TestToolbar")
    
    ' Add a button to the new toolbar
    Dim newButton As AcadToolbarItem
    Dim openMacro As String
    
    ' Assign the macro string the VB equivalent of "ESC ESC _open "
    openMacro = Chr(3) & Chr(3) & Chr(95) & "open" & Chr(32)
    
    Set newButton = newToolBar.AddToolbarButton("", "NewButton", "Open a file.", openMacro)
    
    ' Display the toolbar
    newToolBar.Visible = True
    
End Sub

可视化 LISP:

(vl-load-com)
(defun c:Example_AddToolbarButton()
    ;; This example creates a new toolbar called TestToolbar and inserts a
    ;; toolbar button into it. The toolbar is then displayed.
    ;; To remove the toolbar after execution of this macro, use the Customize Menu
    ;; option from the Tools menu.
    (setq acadObj (vlax-get-acad-object))
    (setq currMenuGroup (vla-Item (vla-get-MenuGroups acadObj) 0))
    
    ;; Create the new toolbar
    (setq newToolBar (vla-Add (vla-get-Toolbars currMenuGroup) "TestToolbar"))
    
    ;; Assign the macro string the VB equivalent of "ESC ESC _open "
    (setq openMacro (strcat (Chr 3) (Chr 3) (Chr 95) "open" (Chr 32)))
    (setq newButton (vla-AddToolbarButton newToolBar "" "NewButton" "Open a file." openMacro))
    
    ;; Display the toolbar
    (vla-put-Visible newToolBar :vlax-true)
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

群   号:715888130

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1   苏公网安备32011402011833)

GMT+8, 2025-5-13 10:34

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部