Get UIApplication anywhere.

Get UIApplication anywhere.

ricaun
Advisor Advisor
770 Views
2 Replies
Message 1 of 3

Get UIApplication anywhere.

ricaun
Advisor
Advisor

UIApplication is the most useful class inside Revit API, give access to all events, documents and can be used to know if your code is in the AddInContext (Revit API Context).

 

Would be really handy is there a way to have access to UIApplication any time you need.

 

There is a way native way in the RevitAPIUI.dll to get UIApplication without any reflection or internal code. I figure out that a long time ago (~3 years) when I was messing with events.

 

The class RibbonItemEventArgs have a directly reference for a new UIApplication class.

 

UIApplication uiapp = new Autodesk.Revit.UI.Events.RibbonItemEventArgs().Application;

 

I created a class RevitApplication in my ricaun.Revit.UI library just to have a base standard.

UIApplication uiapp = RevitApplication.UIApplication;
UIControlledApplication application = RevitApplication.UIControlledApplication;
bool inAddInContext = RevitApplication.IsInAddInContext;

 

Better when that only if Autodesk create a static class like RevitApplication in the RevitAPIUI.dll.

 

That conclude my post, I hope you like it.

 

See yaa!

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes
771 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni

Thank you for the discovery and sharing! Added to the blog:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 3

Sean_Page
Collaborator
Collaborator

I like to use the Application Idle event to get it and the set a static global from there. I am already doing other things there anyway so might as well!

 

private void Application_Idling(object sender, IdlingEventArgs args)
    {
        UIApp = sender as UIApplication;
        AppParams.uiApp = UIApp;
        EnableUpdaters(AppParams.application, "all");
        AppParams.application.Idling -= Application_Idling;
    }
Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes