Adds a toolbar item to a toolbar at a specified position.
Supported platforms: Windows only
VBA:
RetVal = object.AddToolbarButton(Index, Name, HelpString, Macro [, FlyoutButton])
Type: Toolbar
The object this method applies to.
Access: Input-only
Type: Variant
The index location in the toolbar where the item is to be added.
The index must be either an integer or a string. If an integer is specified, the index must be between 0 and N-1, where N is the number of objects in the toolbar. The new item will be added immediately before the specified index location.
Access: Input-only
Type: String
The string that identifies the toolbar button. The string must comprise alphanumeric characters with no punctuation other than a dash (-) or an underscore (_). This string is displayed as the tooltip when the cursor is placed over the toolbar button.
Access: Input-only
Type: String
The string that is displayed in the AutoCAD status line for the button.
Access: Input-only
Type: String
The name of the macro associated with this item.
Access: Input-only; optional
Type: Variant
A Boolean variable stating if the new button is to be a flyout button or not. If the button is a flyout button, this parameter must be set to True. If the button is not a flyout button, this parameter can be set to False or ignored and the new ToolbarItem object will be returned.
You can only add or remove toolbar buttons when the toolbar is visible.
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
Visual 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) )