Here is part of my code. It's basicly copied from the sample. You can see I can set one of the button to disable (fourth last row). But I just don't know how to set it enable or disable dynamically depending a condition. Once I add a If statement, the add-in won't load.
#Region "User interface definition"
' Sub where the user-interface creation is done. This is called when
' the add-in loaded and also if the user interface is reset.
Private Sub AddToUserInterface()
' This is where you'll add code to add buttons to the ribbon.
'** Sample to illustrate creating a button on a new panel of the Tools tab of the Part ribbon.
'** Sample to illustrate creating a button on a new panel of the Tools tab of the Assembly ribbon.
' Get the Assembly ribbon.
Dim assmRibbon As Ribbon = g_inventorApplication.UserInterfaceManager.Ribbons.Item("Assembly")
' Get the "Tools" tab.
Dim assmToolsTab As RibbonTab = assmRibbon.RibbonTabs.Item("id_TabTools")
' Create a new panel.
Dim assmToolPanel As RibbonPanel = assmToolsTab.RibbonPanels.Add("BoMTool", "id_TECO_BoM_Tool", AddInClientID)
' Add a button.
assmToolPanel.CommandControls.AddButton(asmBtnBomNorm, True)
'asmBtnBomNorm.Enabled = Not (g_inventorApplication.ActiveDocument.ComponentDefinition.BOMStructure = BOMStructureEnum.kNormalBOMStructure)
assmToolPanel.CommandControls.AddButton(asmBtnBomInsep, True)
'asmBtnBomInsep.Enabled = Not (g_inventorApplication.ActiveDocument.ComponentDefinition.BOMStructure = BOMStructureEnum.kInseparableBOMStructure)
'UpdateBoMButtons()
'** Sample to illustrate creating a button on a new panel of the Tools tab of the Drawing ribbon.
' Get the Drawing ribbon.
Dim dwgRibbon As Ribbon = g_inventorApplication.UserInterfaceManager.Ribbons.Item("Drawing")
' Get the "Tools" tab.
'Dim dwgToolsTab As RibbonTab = dwgRibbon.RibbonTabs.Item("id_TabTools")
Dim dwgAnnoteTab As RibbonTab = dwgRibbon.RibbonTabs.Item("id_TabAnnotate") ' Move the Buttons to under Annotation
' Create a new panel.
Dim dwgAnnotePanel As RibbonPanel = dwgAnnoteTab.RibbonPanels.Add("TECO", "id_TECO_ToolBox", AddInClientID)
' Add a button.
dwgAnnotePanel.CommandControls.AddButton(m_dwgBtnFind, True)
dwgAnnotePanel.CommandControls.AddButton(m_dwgBtnSpell, True)
m_dwgBtnSpell.Enabled = False
'UpdateBoMButtons()
End Sub