Create Flyout Toolbars

To add a flyout toolbar button to a toolbar, use the AddToolbarButton method. This method creates a new ToolbarItem object and adds it to the designated toolbar.

The AddToolbarButton method takes five parameters as input: Index, Name, HelpString, Macro, and FlyoutButton. By setting the FlyoutButton parameter to TRUE, the new button will be created as a flyout button. The return value from this method will be the new flyout toolbar. The flyout toolbar can then be populated as a normal toolbar would be.

For more information about populating a toolbar, see Add New Toolbar Buttons to a Toolbar.

Create a flyout toolbar button

This example creates two toolbars. The first toolbar contains a flyout button. The second toolbar is attached to the flyout button on the first toolbar.

Sub Ch6_AddFlyoutButton()
	Dim currMenuGroup As AcadMenuGroup
	Set currMenuGroup = ThisDrawing.Application. _

	' Create the first toolbar
	Dim FirstToolbar As AcadToolbar
	Set FirstToolbar = currMenuGroup.Toolbars. _

	' Add a flyout button to the first menu on the menu bar
	Dim FlyoutButton As AcadToolbarItem
	Set FlyoutButton = FirstToolbar.AddToolbarButton _
			("", "Flyout", "Demonstrates a flyout button", _
			 "OPEN", True)

	' Create the second toolbar. This will be attached to
	' the first toolbar via the flyout button.
	Dim SecondToolbar As AcadToolbar
	Set SecondToolbar = currMenuGroup.Toolbars. _

	' Add a button to the next toolbar
	Dim newButton As AcadToolbarItem
	Dim openMacro As String

	' Assign the macro the VB equivalent of "ESC ESC _open "
	openMacro = Chr(3) + Chr(3) + "_open "
	Set newButton = SecondToolbar.AddToolbarButton _
			("", "NewButton", "Open a file.", openMacro)

	' Attach the second toolbar to the flyout
	' button on the first toolbar
	FlyoutButton.AttachToolbarToFlyout currMenuGroup.Name, _

	' Display the first toolbar, hide the second toolbar
	FirstToolbar.Visible = True
	SecondToolbar.Visible = False
End Sub