Message 1 of 2
Problems with External Event in modeless form
Not applicable
01-30-2020
02:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a code for a modeless form and I keep getting an error on starting a transaction. If I use ShowDialog it works fine. I can't seem to figure how to create a working modeless dialog for Revit.
[Transaction(TransactionMode.Manual)]
class FormShow : IExternalCommand
{
public Result Execute(ExternalCommandData c, ref string m, ElementSet e)
{
ExternalEvent x = ExternalEvent.Create(new ExHandler());
UIApplication u = c.Application;
new Form1(x, u).Show();
return Result.Succeeded;
}
class ExHandler : IExternalEventHandler
{
public void Execute(UIApplication ap) { }
public string GetName() { "form1" }
}
}
class Form1 : Form
{
ExternalEvent x;
UIApplication u;
Document d;
public Form1(ExternalEvent e, UIApplication a)
{
InitializeComponent();
x = e;
u = a;
d = u.ActiveUIDocument.Document;
}
private void Button1_Click(object sender, EventArgs e)
{
x.Raise();
using (Transaction t = new Transaction(d, "command"))
{
t.Start();
//do something
t.Commit();
}
this.Close();
}
}