Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

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: 

Get Custom Ribbon Tab name safely

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
TomB.ADV
316 Views, 4 Replies

Get Custom Ribbon Tab name safely

Hi, I'm in the development process of a modular plugin solution where all the buttons are under the same
Ribbon tab but the construction of the Ribbon Panels under this common tab is being done for each module.

Meaning a user may choose to have different combinations of function which I can't predict so naturally

the code assumes it has to create this common tab because the modules aren't "aware" of each other.

The problem is, I can't find a way to check if the tab name is already exists, I can check for panels using:

GetRibbonPanels(string tabName)

I was hoping that calling for panels in a tab which doesn't exists, will return nothing but it throws an exception...

TomBADV_0-1688983405418.png

I tried using same name to check if the .CreateRebbonTab() will just ignore it, but is also throws an exception... 

TomBADV_1-1688983715194.png
I could use try-catch statement but this is typically last resort and overall wrong approach in my opinion

 

            try
            {
                application.CreateRibbonTab("AdvTools");
            }
            catch(Exception)
            {
               //do nothing
            }

 


Are there any decent work-arounds for this situation ?

4 REPLIES 4
Message 2 of 5
jeremy_tammik
in reply to: TomB.ADV

This article shares code to read all ribbon panel titles safely:

  

https://thebuildingcoder.typepad.com/blog/2011/03/ribbon-panel-title-conflict.html

  

I hope this helps. 

  

Best regards,

  

Jeremy

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 5
TomB.ADV
in reply to: jeremy_tammik

I see, so currently the only way to do this is using a private method which will iterate over all the tab names

and return an indicator if it is safe or not to call .CareateRibbonTab()

Message 4 of 5
jeremy_tammik
in reply to: TomB.ADV

Well, maybe not the only way, just one possibility. There may be others, and some may be better. Who knows?

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 5 of 5
ricaun
in reply to: TomB.ADV

To create the RibbonTab that's the way to do it, using a try, to guarantee that the RibbonTab gonna be created.

 

To create the RibbonPanel you gonna need to search and maybe return the existent panel so you could add other buttons in the existent panel.

 

Using some extensions like:

 

public static RibbonPanel CreateOrSelectRibbonPanel(this UIControlledApplication application, string tabName, string panelName)
{
    if (application.GetRibbonPanels(tabName).FirstOrDefault(p => p.Name == panelName) is RibbonPanel ribbonPanel)
        return ribbonPanel;

    return application.CreateRibbonPanel(tabName, panelName);
}
Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

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

Post to forums  

Autodesk Design & Make Report