Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Ribbon ComboBox: Clear/Change Data

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
scolliatie
2520 Views, 11 Replies

Ribbon ComboBox: Clear/Change Data

Hello all,

 

I have a ComboBox that I've created and inserted into a custom Ribbon Tab. On document open, I populate the contents of the ComboBox with a list of 3d views. Everything works great. However, if I were to close that project and open another, I cannot seem to find a way to clear the previous data in the ComboBox. Ideally I'd like to do this when I receive the DropDownOpened callback, to catch any new/deleted views. I am using the 2014 SDK.

 

Thanks

Shane

11 REPLIES 11
Message 2 of 12
scolliatie
in reply to: scolliatie

A little clarification:

This is an Autodesk.Revit.UI.ComboBox that I'm using. The member functions contain AddItem and AddItems, but no RemoveItem or Clear.

Message 3 of 12
Revitalizer
in reply to: scolliatie

Dear scolliatie,

 

since you cannot remove items from the combobox, you need to use a workaround.

 

First, fill your combobox with dummy entries, say 50 to make sure there are enough slots for your 3D views.

 

Then, set the *visibility* property of each item to simulate a dynamic list.

You also can replace both the text and the image at runtime.

 

You just need to adjust the existing combobox items according to your own element list.

If your element list is shorter than 50, all remaining combobox items must be made invisible.

If it is longer than 50, then 50 slots aren't enough 😉

 

This approach will also work for DropDownButtons.

 

 

Best regards,

Revitalizer

 

 




Rudolf Honke
Software Developer
Mensch und Maschine





Message 4 of 12
0001des
in reply to: Revitalizer

Is there any progress on enhancing ribbon comboboxes and other items to handle "remove" "replace" and "Clear?"

Message 5 of 12
Revitalizer
in reply to: 0001des

No - Revit 2019 API does not provide a "RemoveItem" method.

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 6 of 12
0001des
in reply to: Revitalizer

I know there isn't a "remove," "clear," or "insert" method.  I'm basically bumping this thread after several years of waiting.

Message 7 of 12
Revitalizer
in reply to: 0001des

Hi,

 

then please submit an idea or vote up an existing one that matches your needings:

 

https://forums.autodesk.com/t5/revit-ideas/idb-p/302/tab/most-recent

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 8 of 12

I submitted another request for this on the Idea board.

 

https://forums.autodesk.com/t5/revit-ideas/ability-to-remove-combobox-item/idi-p/9553581

Message 9 of 12
Kennan.Chen
in reply to: scolliatie

Since the UI API designed in RevitAPIUI.dll is actually a wrapper around some basic UI controls design in AdWindows.dll. There are two choices for you.

1. Use the undocumented APIs in AdWindows.dll to create your combobox to gain a full access to all the functionalities.

2. Use the documented APIs in RevitAPIUI.dll to create the combobox. Then use reflection to get the wrapped AdWindows UI control and modify it.

Both of the two approaches require an understanding of the undocumented APIs in AdWindows.dll. You may use open source hack tools to uncover it from the dll or just reply on the Visual Studio intellisense to explore yourself.

Message 10 of 12
Anonymous
in reply to: Kennan.Chen

Hello.

 

Could you give an example of initializing or deleting ribbon combobox items using AdWindow?

I know how to get to Autodesk.Windows.RibbonItem.

Message 11 of 12
Kennan.Chen
in reply to: Anonymous

Actually I have some really old code out there on github. Hope it helps! 🙂

 

https://github.com/KennanChan/RevitAPIToolbox/blob/master/RevitAPIToolbox/UI/UIFactory.cs

 

For deleting RibbonItems, the RibbonPanel.Source.Items should provide a Remove method

Message 12 of 12
Anonymous
in reply to: Kennan.Chen

Thanks.

 

I got a hint and I can control the combo box.

Below is the code I tested and made.
It actually works!

 

                var tabRibbon = ComponentManager.Ribbon.FindTab($"{Common.TabNameTest}");
                if (UIApp.GetRibbonPanels(tabRibbon.Name).FirstOrDefault(x => x.Name.Equals(Common.PanelNameTest)) is Autodesk.Revit.UI.RibbonPanel panel)
                {
                    if(tabRibbon.FindItem($"CustomCtrl_%CustomCtrl_%{tabRibbon.Name}%{panel.Name}%LevelsSelector") is RibbonList comboList)
                    {
                        //comboList
                        var addItem = new Autodesk.Windows.RibbonItem
                        {
                            Id = $"CustomCtrl_%CustomCtrl_%CustomCtrl_%{tabRibbon.Name}%{panel.Name}%LevelsSelector%AddLevelTest",
                            Text = "AddLevelTest"
                        };

                        var firstItem = comboList.Items.FirstOrDefault(x => (x as Autodesk.Windows.RibbonItem).Text.Equals("Level 1"));

                        comboList.Items.Remove(firstItem);
                        comboList.Items.Clear();
                        comboList.Items.Add(addItem);
                    }
                }

 

Here, when the first value of the combo box is removed, Current becomes blank and an exception appears in the Current variable of Autodesk.Revit.UI.ComboBox.

Be careful.

.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community