Manipulate Ribbon after application startup

Manipulate Ribbon after application startup

CaoduroC
Enthusiast Enthusiast
721 Views
3 Replies
Message 1 of 4

Manipulate Ribbon after application startup

CaoduroC
Enthusiast
Enthusiast

Good morning,

I saw different examples of addin that are able to add buttons to the ribbon after the application is already running. One of them is Orkestra for example. 
it would be interesting to understand how to interact with the application to be able to create button on the fly if required...

 

0 Likes
Accepted solutions (1)
722 Views
3 Replies
Replies (3)
Message 2 of 4

ricaun
Advisor
Advisor

It's not a good idea to change/add buttons on the fly.

 

But...

 

On the OnStartup you could save the UIControlledApplication and get using static on some command to control the adding/removing panels buttons and stuff.

 

using Autodesk.Revit.UI;

class App : IExternalApplication
{
    public static UIControlledApplication UIControlledApplication()
    {
        return app;
    }

    private static UIControlledApplication app;

    public Result OnStartup(UIControlledApplication application)
    {
        app = application;
        return Result.Succeeded;
    }

    public Result OnShutdown(UIControlledApplication application)
    {
        return Result.Succeeded;
    }
}

Using this on some command/service.

var application = App.UIControlledApplication();

 

One problem to add some buttons on the fly:

  • Revit does not add the button on the shortcut.

A better approach is to add the button on the start and hide the button and only show when needed.

 

See yaa!

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes
Message 3 of 4

Kennan.Chen
Advocate
Advocate

You'll need to use the undocumented lower level APIs in AdWindows.dll to manipulate the ribbon items directly

0 Likes
Message 4 of 4

Kennan.Chen
Advocate
Advocate
Accepted solution

Reference AdWindows.dll, and use Autodesk.Windows.ComponentManager.Ribbon to create/read/update/delete all the RibbonTabs, RibbonPanels and RibbonItems