Message 1 of 2
Once Again: RevitAPI Transaction from ExternalWindow
Not applicable
02-13-2019
09:33 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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:
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);
}
}
}