Update image or text on stacked ribbon item

Update image or text on stacked ribbon item

Anonymous
Not applicable
996 Views
4 Replies
Message 1 of 5

Update image or text on stacked ribbon item

Anonymous
Not applicable

This is about the tooglebutton challenge.

http://thebuildingcoder.typepad.com/blog/2012/11/roll-your-own-toggle-button.html

 

Im testing using the ribbon instead of a windows form.

With the intention to get into a "modeless" state without the need for idling events.

It works brilliantly expect for one thing.

 

Changing pushbutton text and/or image works fine only if the pushbotton is placed directly on the panel.

As its done in the "roll your own toogle button" example.

 

But if the pushbutton is placed stacked or on a slideout it does not work.

When debugging I can verify the values for image and text is actually changing.

So the code runs without errors.

But the ribbon doesnt not update to reflect the change.

Seems there is some hidden stacked "container element" that doesn’t trigger these updates on its stacked members.

 

I looked for methods like "Ribbon.Refresh/Update/Redraw"…something like that.

And also something like "Ribbon.Removeitem" - and then "update by recreating" the ribbonitems.

Seems you can only hide ribbon items, but not remove them.

 

Has anyone worked around this before ?

0 Likes
997 Views
4 Replies
Replies (4)
Message 2 of 5

Mustafa.Salaheldin
Collaborator
Collaborator

Can you provide your sample example to see if I can help?


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

0 Likes
Message 3 of 5

Anonymous
Not applicable

Hi Mustafa

 

I reworked the code to the point of no return.

But i did find a way how to change the image on pushbuttons as stacked, on slideouts and in radiogroups.

You need to use the AdWindows.dll.

 

        public Autodesk.Windows.RibbonItem _GetRibbonItem(string tabName, string panelName, string itemName)
        {
            Autodesk.Windows.RibbonControl ribbon = Autodesk.Windows.ComponentManager.Ribbon;
 
            foreach (Autodesk.Windows.RibbonTab tab in ribbon.Tabs)
            {
                if (tab.Name == tabName)
                {
                    foreach (Autodesk.Windows.RibbonPanel panel in tab.Panels)
                    {
                        if (panel.Source.AutomationName == panelName)
                        {
                            return panel.FindItem("CustomCtrl_%CustomCtrl_%" + tabName + "%" + panelName + "%" + itemName) as Autodesk.Windows.RibbonItem;
                        }
                    }
                }
            }
 
            return null;
 
        }
 
 
 
Basically find the item.
Cast is as appropriate and change the image property.
With the intention to create some kind of toogle button.
It will work.
 

Its a bit strange, AdWindows.dll might be Autodesk's most widely used dll across all their applications.

And yet its not supported in Revit, or at least there is not much info about it.

Im sure its possible to create real toogle/checkboxes on the Revit ribbon as well by using it correctly.

 
I also looked into updating items on a dropdown.
There isnt any "remove item" or update property to use.
The AdWindows.dll can probably solve this as well.
But i could not make it work and just create 50 placeholders and hide the ones i dont need.
 
I played around with something like this: (havent tested this exact code)
The update needs to take place in an Event like DropDownOpened.
 
 public void RemoveDropDownItem(ComboBoxMemberData itemToRemove)
        {
 
            Autodesk.Windows.RibbonCombo rc = VoidRibbon._app._GetRibbonItem("tabName", "panelName", "itemName") as Autodesk.Windows.RibbonCombo;
            ListCollectionView itemsWeCurrentlyHave = rc.ItemsView;
 
            try
            {
                foreach (object dropDownitem in itemsWeCurrentlyHave)
                {
 
                    Autodesk.Revit.UI.ComboBoxMemberData dropItem = dropDownitem as Autodesk.Revit.UI.ComboBoxMemberData;
                   
                    if (dropItem.Text.Equals(itemToRemove.Text))
                    {
                        itemsWeCurrentlyHave.Remove(dropItem);
                    }
 
                }
 
            }
 
            catch
            {
                return;
            }
        }

 

 

 

 

 

Message 4 of 5

Mustafa.Salaheldin
Collaborator
Collaborator

I'm happy to hear that and if there is any further help, I'll be there for you. Smiley Happy


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

0 Likes
Message 5 of 5

Jaime_Alonso
Enthusiast
Enthusiast

I have been trying but I cannot get it working at https://forums.autodesk.com/t5/revit-api-forum/reload-refresh-my-added-toolbar-with-external-command...

Did you find a way around?

0 Likes