Get UIApplication anywhere.
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.
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.
https://github.com/ricaun-io/ricaun.Revit.UI/blob/master/ricaun.Revit.UI/RevitApplication.cs
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!
References
- https://forums.autodesk.com/t5/revit-api-forum/get-uiapplication-anywhere/td-p/13341551