Create a Mini Toolbar

New user-interface elements such as the mini-toolbar were introduced in the 2012 release. The mini-toolbar could be a welcome addition to your application’s user interface and making one is fairly easy. In this example a Visual Basic forms application is used. (Similar steps could be taken to create the toolbar in your Add-In)

Here are the steps to create this example.

1. Using Visual Studio in a Windows Forms application, add a class. (Name it something like clsMiniToolbar). Also add a button to the form.
 
image

2. In the click event for the button have it create a New clsMiniToolBar.

Private Sub Button1_Click _            (ByVal sender As System.Object, _             ByVal e As System.EventArgs) _                            Handles Button1.Click            Dim oMiniToolbar As clsMiniToolbar = _                                New clsMiniToolbar        End Sub

3. At the top of the code window for clsMiniToolbar add the following Imports:

Imports Inventor    Imports System.Runtime.InteropServices

4. Add the following declarations to the class. These variables will be instantiated in the constructor for the class (Sub New) that will be added following this step.

Public Class clsMiniToolbar             Dim invApp As Inventor.Application        Dim started As Boolean             Private WithEvents m_miniToolbar _                             As MiniToolbar        Private WithEvents m_button1 As  _                            MiniToolbarButton        Private WithEvents m_button2 As  _                            MiniToolbarButton        Private WithEvents m_button3 As  _             &
#160;              MiniToolbarButton        Private WithEvents m_combo As  _                            MiniToolbarComboBox        Private WithEvents m_dropDown As  _                            MiniToolbarDropdown

5. Add the Constructor for clsMiniToolbar. When this class is created, the invApp variable is instantiated with the call to GetActiveObject. If this is successful createMiniToolbar is called as long as there is a document open.

Public Sub New()            Try                invApp = Marshal.GetActiveObject _                           ("Inventor.Application")                 Catch ex As Exception                MsgBox _           ("Need to have a session of Inventor running")                Return            End Try                 If invApp.Documents.Count > 0 Then                createMiniToolbar()            Else                MsgBox("Need to have a document open")            End If        End Sub

6. Add the createMiniToolbar Sub Procedure. The CreateMiniToolbar method of the CommandManager is used to instantiate the m_miniToolbar variable. You then use the MiniToolbarControls of the MiniToolbar to add the buttons, ComboBox and Dropdown.

Public Sub createMiniToolbar()                 m_miniToolbar = _             invApp.CommandManager.CreateMiniToolbar                 Dim controls As MiniToolbarControls            controls = m_miniToolbar.Controls                 m_button1 = controls.AddButton _            ("MyButton1", "Button 1", "This is button 1")            m_button2 = controls.AddButton _            ("MyButton2", "Button 2", "This is button 2")            m_button2.AutoHide = True            m_miniToolbar.Controls.AddSeparator()            m_button3 = controls.AddButton _            ("MyButton3", "Button 3", "This is button 3")                 controls.AddNewLine()                 m_combo = controls.AddComboBox _                      ("MyCombo", True, True, 35)            m_combo.AddItem _                ("Item 1", "Item number 1", , True)            m_combo.AddItem _                ("Item 2", "Item number 2", , False)            m_combo.AddItem _                ("Item 3", "Item number 3", , False)            m_combo.AddItem _                ("Item 4", "Item number 4", , True)            controls.AddLabel _                ("MyLabel", "Some stuff:", "Stuff")                 m_dropDown = controls.AddDropdown _                ("MyDropdown", True, True, True)            m_dropDown.AddItem _                ("Thing 1", "Thing 1 tooltip", , , , )            m_dropDown.AddItem _                ("Thing 2", "Thing 2 tooltip")            m_dropDown.AddItem _                ("Thing 3", "Thing 3 tooltip", , , , )                 m_miniToolbar.Visible = True             End Sub

When the createMiniToolbar procedure is run it will create this Mini Toolbar:

image

7. Now we need to add the events that will run when the user interacts with controls on the mini toolbar. In this example we are just providing feedback that the event occurred. (Note: If you try this example, the MsgBox items may be behind the Inventor Window.)

Private Sub m_button1_OnClick1() _                          Handles m_button1.OnClick            MsgBox("Clicked ""Button 1""")        End Sub             Private Sub m_button2_OnClick1() _                           Handles m_button2.OnClick            MsgBox("Clicked ""Button 2""")        End Sub        Private Sub m_button3_OnClick1() _                            Handles m_button3.OnClick            MsgBox("Clicked ""Button 3""")        End Sub             Private Sub m_combo_OnSelect1 _       (ByVal ListItem As Inventor.MiniToolbarListItem) _                               Handles m_combo.OnSelect            MsgBox("Combo selected: " & ListItem.Text)        End Sub             Private Sub m_combo_OnItemHoverEnd1 _       (ByVal ListItem As Inventor.MiniToolbarListItem) _                          Handles m_combo.OnItemHoverEnd            Debug.Print _             ("Hovered ended over item """ _                             & ListItem.Text & """")        End Sub             Private Sub m_combo_OnItemHoverStart1 _       (ByVal ListItem As Inventor.MiniToolbarListItem) _                         Handles m_combo.OnItemHoverStart            Debug.Print _               ("Hovered started over item """ _                               & ListItem.Text & """")        End Sub             Private Sub m_combo_OnItemRemove _       (ByVal ListItem As Inventor.MiniToolbarListItem) _                            Handles m_combo.OnItemRemove            MsgBox("Item removed: """ _                                 & ListItem.Text & """")        End Sub             Private Sub m_dropDown_OnSelect1 _       (ByVal ListItem As Inventor.MiniToolbarListItem) _                             Handles m_dropDown.OnSelect            Debug.Print("Dropdown selected: ", _                                         ListItem.Text)        End Sub             Private Sub m_miniToolbar_OnApply() _                          Handles m_miniToolbar.OnApply            MsgBox("Clicked ""Apply""")        End Sub             Private Sub m_miniToolbar_OnCancel() _                         Handles m_miniToolbar.OnCancel            MsgBox("Clicked ""Cancel""")            m_miniToolbar = Nothing            m_button1 = Nothing            m_button2 = Nothing            m_button3 = Nothing            m_combo = Nothing        End Sub             Private Sub m_miniToolbar_OnOK() _                          Handles m_miniToolbar.OnOK            MsgBox("Clicked ""Ok""")            m_miniToolbar = Nothing            m_button1 = Nothing            m_button2 = Nothing            m_button3 = Nothing            m_combo = Nothing        End Sub

(End of the example)

The mini toolbars will be a nice addition to the user interface for your application. The Inventor 2012 API gives you the ability to create these floating, transparent replacements to dialog interfaces.

The API for mini toolbars Support the following:

  • Apply, OK, Cancel buttons
  • New lines and separators
  • Button
  • Check box
  • Combo box
  • Drop-downs

Mini toolbars are also supported within a command (InteractionEvents) and at Application level (CommandManager) as in this example.

Wayne Brill


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading