Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adding Combo Boxes to Ribbon Panels

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
3743 Views, 7 Replies

Adding Combo Boxes to Ribbon Panels

I preparing an addin written in VB.NET VS2008 which allows uses to do several different function depending on the type of document opened and the ribbon environment active.

 

I have add lots of different icons/buttons to execute simple runtime commands, but I wish to develop my code a little better.

 

I currently have code that when the button is pressed opens a form with a combo box. If the active file opened in the workspace is as Assembly Document, the combo box is populated with the colors from the Styles Library. Once the user selects a colour, the program then cycles through all of the parts in the assembly and changes the colour at the part level be that which the user has selected.

 

I would like to short cut around opening the form and maybe add a combo box definition directly to my custom panel that I have created in the "id_TabAssemble" Tab ribbon.

 

So I guess my question is does someone have a snippet of code which adds a combo box to a ribbon Tab panel and allows that combo box to populated with whatever the user desires.

 

People may say that this is already done with the colour combobox that is in the Quick Tool menu for assemblies, however this colour change is only at the view rep level and not at the part level, if the part is used again in a different assembly the colour will be the original colour.

 

Any help will be greatly appreciated Smiley Very Happy

7 REPLIES 7
Message 2 of 8
YuhanZhang
in reply to: Anonymous

There is an addin sample in VB.Net in Inventor SDK(DeveloperTools\Samples\VB.NET\AddIns\SimpleAddIn), you can try it and see how to add a combobox onto ribbon. But you need to add the render styles(colors) into the combobox, and add an ComboBoxDefinition.OnSelect event to detect which item user selects.

 

Hope this helps.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 3 of 8
Anonymous
in reply to: YuhanZhang

Rocky,

 

Thanks for the help, I have managed to get the Combo Box into my custom ribbon with the Colours, however I am a little lost with the whole .OnSelect Event, can you point me in a direction where I can find some information on what to program to enable the user to select the colour and then the part changes.

 

Mark

Message 4 of 8
YuhanZhang
in reply to: Anonymous

Hi Mark,

 

Good to hear that you have got the combo box on your ribbon. For how to make it to change the color of a part I would recommend below sample from API help document:

 

'***********************************************
' 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

 

The sample is a VBA code sample, so you can easily try it and see how it(OnSelect) works. As the sample was designed for classic UI, I modified it a bit so you can also use it in ribbon UI, after you run the macro CreateComboBox, then a toolbar would display and the first combo box is the one added, and you can choose a Material in it to see the change. What you need to do is to change the Material to RenderStyle for your case.

 

Hope this helps!



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 5 of 8
Anonymous
in reply to: Anonymous

Rocky,

 

Thanks for the information, however this is for VBA, I am writting my code in VB.NET. I have managed to create an _OnSelect Event for the Combobox. While testing I have enter a simple Msgbox to appear once the combo box is used while I debug the program.

 

However something weird is happening. When I load inventor, the msgbox is activating. This is telling me that the combo box OnSelect event is being activated when the Addin is being initialised. If I was able to send my VB.NET project code to you would be kind enough to have a look for me and see what I am doing wrong.

 

Mark

Message 6 of 8
YuhanZhang
in reply to: Anonymous

Hi Mark,

 

The OnSelect event could also be fired if you set the ComboBoxDefinition.ListIndex via API, so could you check your code if you have it to set a value?



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 7 of 8
amitnkukanur
in reply to: YuhanZhang

But any ideas on how to create New Ribbon Tabs.

 

Senior Software Engineer
Message 8 of 8
shashankagam
in reply to: Anonymous

hello, i am new on inventor API, so can you share your code that when the button is pressed opens a form with a combo box. If the active file opened in the workspace is as Assembly Document, the combo box is populated with the colors from the Styles Library. Once the user selects a colour, the program then cycles through all of the parts in the assembly and changes the colour at the part level be that which the user has selected.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report