Message 1 of 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
what are best practices with accessing UIApplication and ExternalCommandData ?
Do you use static DTOs, like these:
internal class RevitUiApplicationDTO
{
public static UIApplication UiApp { get; set; }
public static UIDocument UiDoc => UiApp?.ActiveUIDocument;
public static Document Doc => UiDoc?.Document;
}
public static class RevitExternalCommandDTO
{
public static ExternalCommandData CommandData { get; set; }
public static UIApplication UiApp => CommandData?.Application;
public static UIDocument UiDoc => UiApp?.ActiveUIDocument;
public static Document Doc => UiDoc?.Document;
}
this seems like easy solution that solves passing around the UiApp or CommandData.
I set it when i subscribe to Idling event, and it works with first manual tests.
public class IdlingEventHandler : IExternalEventHandler
{
public void Execute(UIApplication uiApplication)
{
uiApplication.Idling += IdlingHandler;
RevitUiApplicationDTO.UiApp = uiApplication;
}
public void IdlingHandler(object sender, Autodesk.Revit.UI.Events.IdlingEventArgs args)
{
if (ChatInputPageIsValid())
ProcessRequest(RevitUiApplicationDTO.UiApp);
else
UnsubscribeIdling(RevitUiApplicationDTO.UiApp);
}
Later when i would automate testing with Geberit Revit Unit testing https://github.com/geberit/Revit.TestRunner ,I would still set UIapp as DTO.
[OneTimeSetUp]
public void Setup(UIApplication uiApplication)
{
Assert.NotNull(uiApplication);
RevitUiApplicationDTO.UiApp = uiApplication;
}
Will I get in trouble later down the road for using this method of passing the UIapp around ?
I use Idling event because all Commands will be initiated from Modeless docked pane.
Solved! Go to Solution.