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.
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.
Solved by ricaun. Go to Solution.
Using Idling is a good way to do it, tecnaly you only need to store the UIApplication once, and is good to go.
Today I converted the UIControllerApplication to UIApplication, so I don't need to worry about registering events.
Using this extension: https://github.com/ricaun-io/RevitAddin.DI.Simple/blob/master/RevitAddin.DI.Simple/Extensions/UICont...
public Result OnStartup(UIControlledApplication application)
{
UIApplication uiapp = application.GetUIApplication();
}
Storing the ExternalCommandData is not a thing I do, ExternalCommandData is only used inside an IExternalCommand, kinda useless outside that context.
Using Idling is a good way to do it, tecnaly you only need to store the UIApplication once, and is good to go.
Today I converted the UIControllerApplication to UIApplication, so I don't need to worry about registering events.
Using this extension: https://github.com/ricaun-io/RevitAddin.DI.Simple/blob/master/RevitAddin.DI.Simple/Extensions/UICont...
public Result OnStartup(UIControlledApplication application)
{
UIApplication uiapp = application.GetUIApplication();
}
Storing the ExternalCommandData is not a thing I do, ExternalCommandData is only used inside an IExternalCommand, kinda useless outside that context.
Can't find what you're looking for? Ask the community or share your knowledge.