<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Set combobox item active in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/set-combobox-item-active/m-p/6496056#M107552</link>
    <description>&lt;P&gt;anyone ?&lt;/P&gt;</description>
    <pubDate>Fri, 12 Aug 2016 06:51:39 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-08-12T06:51:39Z</dc:date>
    <item>
      <title>Set combobox item active</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/set-combobox-item-active/m-p/6486909#M107551</link>
      <description>&lt;P&gt;Hi, I have made a combobox in the ribbon with 5 sheet sizes. What I want is to set the combobox item active corresponding the opened drawing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, when I open an A3 sheet, I want set the active item in the combobox to the same value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;combobox.ListIndex = 4&lt;/P&gt;&lt;P&gt;combobox.set_ListItem(4,"A3")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the combobox stays at it's initial value &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HOw can I achieve this ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2016 09:55:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/set-combobox-item-active/m-p/6486909#M107551</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-08-09T09:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: Set combobox item active</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/set-combobox-item-active/m-p/6496056#M107552</link>
      <description>&lt;P&gt;anyone ?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2016 06:51:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/set-combobox-item-active/m-p/6496056#M107552</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-08-12T06:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: Set combobox item active</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/set-combobox-item-active/m-p/6496143#M107553</link>
      <description>&lt;P&gt;Can you post the piece of code that actually retrieves the combobox you've created?&lt;/P&gt;&lt;P&gt;That would save me a lot of reproduction time&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Met vriendelijke groeten&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2016 07:56:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/set-combobox-item-active/m-p/6496143#M107553</guid>
      <dc:creator>frederic.vandenplas</dc:creator>
      <dc:date>2016-08-12T07:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: Set combobox item active</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/set-combobox-item-active/m-p/6502334#M107554</link>
      <description>&lt;P&gt;public void SetSheetFormat(Application inventapp)&lt;BR /&gt;{&lt;BR /&gt;DrawingDocument doc = inventapp.ActiveDocument as DrawingDocument;&lt;BR /&gt;if (doc == null) return;&lt;BR /&gt;CommandManager cmdman = inventapp.CommandManager;&lt;BR /&gt;ControlDefinitions ctrldefs = cmdman.ControlDefinitions;&lt;BR /&gt;ComboBoxDefinition cmbdef = ctrldefs["SheetFormats"] as ComboBoxDefinition;&lt;BR /&gt;if (cmbdef == null) return;&lt;BR /&gt;Sheet sheet = doc.ActiveSheet;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//&amp;nbsp;Okay, so here I get the size of the loaded document. Then I want my combobox to display this value&lt;BR /&gt;/*&lt;BR /&gt;DrawingSheetSizeEnum dform = sheet.Size;&lt;BR /&gt;switch (dform)&lt;BR /&gt;{&lt;BR /&gt;case DrawingSheetSizeEnum.kA0DrawingSheetSize:&lt;BR /&gt;cmbdef.ListIndex = 1;&lt;BR /&gt;break;&lt;BR /&gt;case DrawingSheetSizeEnum.kA1DrawingSheetSize:&lt;BR /&gt;cmbdef.ListIndex = 2;&lt;BR /&gt;break;&lt;BR /&gt;case DrawingSheetSizeEnum.kA2DrawingSheetSize:&lt;BR /&gt;cmbdef.ListIndex = 3; // tried this with no effect&lt;BR /&gt;break;&lt;BR /&gt;case DrawingSheetSizeEnum.kA3DrawingSheetSize:&lt;BR /&gt;cmbdef.set_ListItem(4, "A3");&amp;nbsp;&lt;SPAN&gt;// tried this with no effect&lt;/SPAN&gt;&lt;BR /&gt;break;&lt;BR /&gt;case DrawingSheetSizeEnum.kA4DrawingSheetSize:&lt;BR /&gt;cmbdef.ListIndex = 5;&lt;BR /&gt;break;&lt;BR /&gt;}&lt;BR /&gt;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I can't figure out how to change the selected index of a combobox in a ribbon.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 07:41:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/set-combobox-item-active/m-p/6502334#M107554</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-08-16T07:41:05Z</dc:date>
    </item>
    <item>
      <title>Re: Set combobox item active</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/set-combobox-item-active/m-p/6502426#M107555</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've recreated this in vba (easier for debugging) and this worked for me&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Public Sub setComboItem()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dim cmdman As CommandManager&lt;BR /&gt;Set cmdman = ThisApplication.CommandManager&lt;BR /&gt;Dim ctrldefs As ControlDefinitions&lt;BR /&gt;Set ctrldefs = cmdman.ControlDefinitions&lt;BR /&gt;Dim cmbdef As ComboBoxDefinition&lt;BR /&gt;Set cmbdef = ctrldefs.Item("SheetSizeCombobox--&amp;gt; you need to change this to the internal name of the combobox")&lt;/P&gt;&lt;P&gt;If cmbdef Is Nothing Then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return&lt;BR /&gt;Else&lt;BR /&gt;'find the sheetsize and set the listindex according to the value&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cmbdef.ListIndex = 1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;End Sub&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've created a comobobox using this snippet below from another post for my convenience.&lt;/P&gt;&lt;PRE&gt;'***********************************************
' Copy below code to a module 
Public oChangeMaterial As clsChangeMaterial

Public Sub CreateComboBox()
    ' Set a reference to the active document.
    ' This assumes that a part document is active.
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oCommandMgr As CommandManager
    Set oCommandMgr = ThisApplication.CommandManager
    
    ' Set a reference to the collection of ControlDefinitions
    Dim oControlDefs As ControlDefinitions
    Set oControlDefs = oCommandMgr.ControlDefinitions
    
    On Error Resume Next
    ' Create a combobox definition
    Dim oComboBoxDef As ComboBoxDefinition
    Set oComboBoxDef = oControlDefs.Item("MaterialsComboBox")
    
    If oComboBoxDef Is Nothing Then
        Set oComboBoxDef = oControlDefs.AddComboBoxDefinition("Materials", "MaterialsComboBox", kNonShapeEditCmdType, 125, , "Materials Combo", "Materials")
        
        ' Set a reference to the materials collection.
        Dim oMaterials As Materials
        Set oMaterials = oDoc.Materials
        
        Dim oMaterial As Material
        
        For Each oMaterial In oMaterials
            ' Add material names to the combo box definition
            oComboBoxDef.AddItem (oMaterial.Name)
        Next
        
        ' Set a reference to the Part Standard toolbar
        Dim oPartFeatureToolbar As CommandBar
        Set oPartFeatureToolbar = ThisApplication.UserInterfaceManager.CommandBars.Item("PMxPartFeatureCmdBar")
        
        ' Add a combo box control to the toolbar
        Dim oComboBoxControl As CommandBarControl
        Set oComboBoxControl = oPartFeatureToolbar.Controls.AddComboBox(oComboBoxDef,1)
        
        oPartFeatureToolbar.Visible = True    
    End If
    
    ' Clear current selection
    oComboBoxDef.ListIndex = 0
  
    Set oChangeMaterial = New clsChangeMaterial
    oChangeMaterial.Initialize
End Sub


'*************************************************************
' The declarations and functions below need to be copied into
' a class module whose name is "clsChangeMaterial".  The name 
' can be changed but you'll need to change the declaration in
' the calling function "CreateComboBox" to use the new name.

Option Explicit
Private WithEvents oComboBoxDef As ComboBoxDefinition


Public Sub Initialize()

    Dim oCommandMgr As CommandManager
    Set oCommandMgr = ThisApplication.CommandManager
   
    ' Set a reference to the collection of ControlDefinitions
    Dim oControlDefs As ControlDefinitions
    Set oControlDefs = oCommandMgr.ControlDefinitions
    
    ' Set a reference to the "MaterialsComboBox" combo box definition
    Set oComboBoxDef = oControlDefs.Item("MaterialsComboBox")
        
End Sub

Private Sub oComboBoxDef_OnSelect(ByVal Context As NameValueMap)
    
    If oComboBoxDef.ListIndex = 0 Then
        Exit Sub
    End If
    
    ' Get the selected item
    Dim oMaterialName As String
    oMaterialName = oComboBoxDef.ListItem(oComboBoxDef.ListIndex)
    
    ' Set a reference to the active part document
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oPartCompDef As PartComponentDefinition
    Set oPartCompDef = oDoc.ComponentDefinition
    
    ' Get the selected material
    Dim oMaterial As Material
    Set oMaterial = oDoc.Materials.Item(oMaterialName)
    
    ' Change the part material
    oPartCompDef.Material = oMaterial
End Sub&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Aug 2016 08:36:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/set-combobox-item-active/m-p/6502426#M107555</guid>
      <dc:creator>frederic.vandenplas</dc:creator>
      <dc:date>2016-08-16T08:36:13Z</dc:date>
    </item>
  </channel>
</rss>

