Once Again: RevitAPI Transaction from ExternalWindow

Once Again: RevitAPI Transaction from ExternalWindow

Anonymous
Not applicable
420 Views
1 Reply
Message 1 of 2

Once Again: RevitAPI Transaction from ExternalWindow

Anonymous
Not applicable

Dear All,

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.

Obviously, the error I get: "Transactions are not allowed outside valid RevitAPI context" and I know that I should use ExternalEvents:

(https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/Revit-API/files/GUID-...)

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?

Much Appreciated, Lukasz

 

 

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<Element> CheckedElements = new List<Element>();

        public TasksWindow(Document doc)
        {
            InitializeComponent();
            this.Document = doc;
        }

        private void Apply_Click(object sender, RoutedEventArgs e)
        {
            //  <---    HOW TO IMPLEMENT SOLUTION HERE ? ---->
            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);
        }
    }
}

 

 

 

0 Likes
421 Views
1 Reply
Reply (1)
Message 2 of 2

jeremytammik
Autodesk
Autodesk

Look at the Revit SDK sample on external events.

 

If you are still stuck after that, you should give up and do something else  🙂

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes