<?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 Once Again: RevitAPI Transaction from ExternalWindow in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/once-again-revitapi-transaction-from-externalwindow/m-p/8593410#M44215</link>
    <description>&lt;P&gt;Dear All,&lt;/P&gt;
&lt;P&gt;I have read all the posts regarding my problem, however still I don't know how to solve it. I am using IExternalApplication interface to call a WPF Window (in my case - class TaskWindow) to perform some events in Revit API.&lt;/P&gt;
&lt;P&gt;Obviously, the error I get: "Transactions are not allowed outside valid RevitAPI context" and I know that I should use &lt;STRONG&gt;ExternalEvents&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#3366FF"&gt; (&lt;A href="https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/Revit-API/files/GUID-0A0D656E-5C44-49E8-A891-6C29F88E35C0-htm.html" target="_blank"&gt;https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/Revit-API/files/GUID-0A0D656E-5C44-49E8-A891-6C29F88E35C0-htm.html&lt;/A&gt;) &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;However, due to lack of my knowledge, I am stuck a bit. Can someone of you guys, give me a hint in relation to my code below?&lt;/P&gt;
&lt;P&gt;Much Appreciated, Lukasz&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using Autodesk.Revit.DB;

namespace DockableDialogs
{
    public partial class TasksWindow : Window
    {
        public Document Document = null;
        public List&amp;lt;Element&amp;gt; CheckedElements = new List&amp;lt;Element&amp;gt;();

        public TasksWindow(Document doc)
        {
            InitializeComponent();
            this.Document = doc;
        }

        private void Apply_Click(object sender, RoutedEventArgs e)
        {
            //  &amp;lt;---    HOW TO IMPLEMENT SOLUTION HERE ? ----&amp;gt;
            using (Transaction tx = new Transaction(this.Document, "MarkChecked"))
            {
                tx.Start();
                foreach (Element el in CheckedElements)
                {
                    try
                    {
                        el.LookupParameter("SomeVisibilityParameter").Set(0);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                tx.Commit();
            }
            this.Close();
        }

        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            //Get some elements for the CheckedElements list
            Element target = ((Element)((CheckBox)sender).Content);
            this.CheckedElements.Add(target);
        }
    }
}
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Feb 2019 17:33:24 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-02-13T17:33:24Z</dc:date>
    <item>
      <title>Once Again: RevitAPI Transaction from ExternalWindow</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/once-again-revitapi-transaction-from-externalwindow/m-p/8593410#M44215</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;
&lt;P&gt;I have read all the posts regarding my problem, however still I don't know how to solve it. I am using IExternalApplication interface to call a WPF Window (in my case - class TaskWindow) to perform some events in Revit API.&lt;/P&gt;
&lt;P&gt;Obviously, the error I get: "Transactions are not allowed outside valid RevitAPI context" and I know that I should use &lt;STRONG&gt;ExternalEvents&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#3366FF"&gt; (&lt;A href="https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/Revit-API/files/GUID-0A0D656E-5C44-49E8-A891-6C29F88E35C0-htm.html" target="_blank"&gt;https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/Revit-API/files/GUID-0A0D656E-5C44-49E8-A891-6C29F88E35C0-htm.html&lt;/A&gt;) &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;However, due to lack of my knowledge, I am stuck a bit. Can someone of you guys, give me a hint in relation to my code below?&lt;/P&gt;
&lt;P&gt;Much Appreciated, Lukasz&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using Autodesk.Revit.DB;

namespace DockableDialogs
{
    public partial class TasksWindow : Window
    {
        public Document Document = null;
        public List&amp;lt;Element&amp;gt; CheckedElements = new List&amp;lt;Element&amp;gt;();

        public TasksWindow(Document doc)
        {
            InitializeComponent();
            this.Document = doc;
        }

        private void Apply_Click(object sender, RoutedEventArgs e)
        {
            //  &amp;lt;---    HOW TO IMPLEMENT SOLUTION HERE ? ----&amp;gt;
            using (Transaction tx = new Transaction(this.Document, "MarkChecked"))
            {
                tx.Start();
                foreach (Element el in CheckedElements)
                {
                    try
                    {
                        el.LookupParameter("SomeVisibilityParameter").Set(0);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                tx.Commit();
            }
            this.Close();
        }

        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            //Get some elements for the CheckedElements list
            Element target = ((Element)((CheckBox)sender).Content);
            this.CheckedElements.Add(target);
        }
    }
}
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 17:33:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/once-again-revitapi-transaction-from-externalwindow/m-p/8593410#M44215</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-02-13T17:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: Once Again: RevitAPI Transaction from ExternalWindow</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/once-again-revitapi-transaction-from-externalwindow/m-p/8594945#M44216</link>
      <description>&lt;P&gt;Look at the Revit SDK sample on external events.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are still stuck after that, you should give up and do something else&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 06:18:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/once-again-revitapi-transaction-from-externalwindow/m-p/8594945#M44216</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2019-02-14T06:18:12Z</dc:date>
    </item>
  </channel>
</rss>

