Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Static UIApplication & ExternalCommandData DTOs

1 REPLY 1
SOLVED
Reply
Message 1 of 2
esatis
183 Views, 1 Reply

Static UIApplication & ExternalCommandData DTOs

esatis
Advocate
Advocate

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. 

0 Likes

Static UIApplication & ExternalCommandData DTOs

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. 

1 REPLY 1
Message 2 of 2
ricaun
in reply to: esatis

ricaun
Advisor
Advisor
Accepted 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.

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

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.

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report