<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Static UIApplication &amp;amp; ExternalCommandData DTOs in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/static-uiapplication-amp-externalcommanddata-dtos/m-p/12457668#M7956</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;what are best practices with accessing UIApplication and&amp;nbsp;ExternalCommandData ?&amp;nbsp;&lt;BR /&gt;Do you use static DTOs, like these:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class RevitUiApplicationDTO
{
	public static UIApplication UiApp { get; set; }
	public static UIDocument UiDoc =&amp;gt; UiApp?.ActiveUIDocument;
	public static Document Doc =&amp;gt; UiDoc?.Document;
}

public static class RevitExternalCommandDTO
{
    public static ExternalCommandData CommandData { get; set; }
    public static UIApplication UiApp =&amp;gt; CommandData?.Application;
    public static UIDocument UiDoc =&amp;gt; UiApp?.ActiveUIDocument;
    public static Document Doc =&amp;gt; UiDoc?.Document;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this seems like easy solution that solves passing around the UiApp or CommandData.&lt;/P&gt;&lt;P&gt;I set it when i subscribe to Idling event, and it works with first manual tests.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;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);
	}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Later when i would automate testing with Geberit Revit Unit&amp;nbsp;testing&amp;nbsp;&lt;A href="https://github.com/geberit/Revit.TestRunner" target="_blank"&gt;https://github.com/geberit/Revit.TestRunner&lt;/A&gt;&amp;nbsp;,I would still set UIapp as DTO.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;		[OneTimeSetUp]
		public void Setup(UIApplication uiApplication)
		{

			Assert.NotNull(uiApplication);
RevitUiApplicationDTO.UiApp = uiApplication;

		}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp; Will I get in trouble later down the road for using this method of passing the UIapp around ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use Idling event because all Commands will be initiated from Modeless docked pane.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 22 Dec 2023 09:59:17 GMT</pubDate>
    <dc:creator>esatis</dc:creator>
    <dc:date>2023-12-22T09:59:17Z</dc:date>
    <item>
      <title>Static UIApplication &amp; ExternalCommandData DTOs</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/static-uiapplication-amp-externalcommanddata-dtos/m-p/12457668#M7956</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;what are best practices with accessing UIApplication and&amp;nbsp;ExternalCommandData ?&amp;nbsp;&lt;BR /&gt;Do you use static DTOs, like these:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class RevitUiApplicationDTO
{
	public static UIApplication UiApp { get; set; }
	public static UIDocument UiDoc =&amp;gt; UiApp?.ActiveUIDocument;
	public static Document Doc =&amp;gt; UiDoc?.Document;
}

public static class RevitExternalCommandDTO
{
    public static ExternalCommandData CommandData { get; set; }
    public static UIApplication UiApp =&amp;gt; CommandData?.Application;
    public static UIDocument UiDoc =&amp;gt; UiApp?.ActiveUIDocument;
    public static Document Doc =&amp;gt; UiDoc?.Document;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this seems like easy solution that solves passing around the UiApp or CommandData.&lt;/P&gt;&lt;P&gt;I set it when i subscribe to Idling event, and it works with first manual tests.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;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);
	}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Later when i would automate testing with Geberit Revit Unit&amp;nbsp;testing&amp;nbsp;&lt;A href="https://github.com/geberit/Revit.TestRunner" target="_blank"&gt;https://github.com/geberit/Revit.TestRunner&lt;/A&gt;&amp;nbsp;,I would still set UIapp as DTO.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;		[OneTimeSetUp]
		public void Setup(UIApplication uiApplication)
		{

			Assert.NotNull(uiApplication);
RevitUiApplicationDTO.UiApp = uiApplication;

		}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp; Will I get in trouble later down the road for using this method of passing the UIapp around ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use Idling event because all Commands will be initiated from Modeless docked pane.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Dec 2023 09:59:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/static-uiapplication-amp-externalcommanddata-dtos/m-p/12457668#M7956</guid>
      <dc:creator>esatis</dc:creator>
      <dc:date>2023-12-22T09:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: Static UIApplication &amp; ExternalCommandData DTOs</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/static-uiapplication-amp-externalcommanddata-dtos/m-p/12457963#M7957</link>
      <description>&lt;P&gt;Using &lt;STRONG&gt;Idling&lt;/STRONG&gt; is a good way to do it, tecnaly you only need to store the &lt;STRONG&gt;UIApplication&lt;/STRONG&gt; once, and is good to go.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Today I converted the &lt;STRONG&gt;UIControllerApplication&lt;/STRONG&gt; to &lt;STRONG&gt;UIApplication&lt;/STRONG&gt;, so I don't need to worry about registering events.&lt;/P&gt;&lt;P&gt;Using this extension: &lt;A href="https://github.com/ricaun-io/RevitAddin.DI.Simple/blob/master/RevitAddin.DI.Simple/Extensions/UIControlledApplicationExtension.cs" target="_blank" rel="noopener"&gt;https://github.com/ricaun-io/RevitAddin.DI.Simple/blob/master/RevitAddin.DI.Simple/Extensions/UIControlledApplicationExtension.cs&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public Result OnStartup(UIControlledApplication application)
{
	UIApplication uiapp = application.GetUIApplication();
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Storing the &lt;STRONG&gt;ExternalCommandData&lt;/STRONG&gt; is not a thing I do, &lt;STRONG&gt;ExternalCommandData&lt;/STRONG&gt; is only used inside an &lt;STRONG&gt;IExternalCommand&lt;/STRONG&gt;, kinda useless outside that context.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Dec 2023 16:35:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/static-uiapplication-amp-externalcommanddata-dtos/m-p/12457963#M7957</guid>
      <dc:creator>ricaun</dc:creator>
      <dc:date>2023-12-22T16:35:45Z</dc:date>
    </item>
  </channel>
</rss>

