Inventor.ButtonDefinition for multiple buttons

Inventor.ButtonDefinition for multiple buttons

w.pepping
Advocate Advocate
970 Views
3 Replies
Message 1 of 4

Inventor.ButtonDefinition for multiple buttons

w.pepping
Advocate
Advocate

I have an add-in that creates multiple buttons (in a separate panel) within the ribbon-tabs.

If I use this, only the last added button can be fired: 

 Private WithEvents m_Button As ButtonDefinition
 Private Sub m_Button_OnExecute(Context As NameValueMap) Handles m_Button.OnExecute
        '  action here....
 End Sub

 I have also tried to put all ButtonDefinitions in a list. All buttons can be fired now, but I cannot find out which button is fired.

  Private WithEvents ButtonList As New List(Of ButtonDefinition)

Gives the Inventor API a solution for this, or is there a good workaround?

 

Get control of your sheet metal files.
Download the app from matprop.com
0 Likes
Accepted solutions (1)
971 Views
3 Replies
Replies (3)
Message 2 of 4

matt_jlt
Collaborator
Collaborator

Hi, if i am reading your question correctly, what you need to do is create a new button definition for each button. Then add each of those to your button collection. That's my best guess for the limited information you provided.

 

 Private WithEvents m_Button1 As ButtonDefinition
 Private Sub m_Button1_OnExecute(Context As NameValueMap) Handles m_Button1.OnExecute
        '  action here....
 End Sub

 Private WithEvents m_Button2 As ButtonDefinition
 Private Sub m_Button2_OnExecute(Context As NameValueMap) Handles m_Button2.OnExecute
        '  action here....
 End Sub

 

Hopefully this helps.

 

Regards, Matt.

0 Likes
Message 3 of 4

w.pepping
Advocate
Advocate

Thank you Matt.

Your solution works if you know which buttons you have. In my case the buttons are read from a configurable XML file. So I don't know how many buttons there will be. To make the code easier, I try to put the ButtonDefinitions in a collection first.

Get control of your sheet metal files.
Download the app from matprop.com
0 Likes
Message 4 of 4

w.pepping
Advocate
Advocate
Accepted solution

I have found a solution to assign multiple buttons in case the number of buttons and their actions need to be configurable. In my case they are read from an XML file.

For this I have modified the code in this post from Philippe Leefsma.

I removed the 'ReplaceNativeControls'  and added the buttons into a custom panel in the ribbon.

    Private _customButtonDefinition As ButtonDefinition
  
Public Sub New(objNode As XmlNode, oButtonConfig As String)     
   dim m_DynamicRibbon As Ribbon = g_inventorApplication.UserInterfaceManager.Ribbons.Item(DynamicRibbon)
   dim m_DynamicTab As RibbonTab = m_DynamicRibbon.RibbonTabs.Item(DynamicTab)
dim PanelIndex as string = "RibbonUI" & DynamicTab
        Try
           dim m_DynamicPanel As RibbonPanel = m_DynamicTab.RibbonPanels.Item(ControlChars.Quote & PanelIndex & ControlChars.Quote)
        Catch ex As Exception
        End Try
        If m_DynamicPanel Is Nothing Then m_DynamicPanel = m_DynamicTab.RibbonPanels.Add("Cadix", PanelIndex, g_addInClientID)
        m_DynamicPanel.CommandControls.AddButton(_customButtonDefinition, True)
End Sub

 

Get control of your sheet metal files.
Download the app from matprop.com