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();
}
}
You'll have more answers if you post this question in the Revit API forum.
You are using a modeless form so it is not connected to revit, you cant start transactions from a modeless form.
You'll need to create an idling event and use a transaction from a command.
1 - in the command you use to show the form add an idling event
2 - create a public bool.
3 - in the form when you on click button event change the bool to true.
4 - in the idling event handling wright: if(bool){my transaction......bool = false.}
Hope it helps
Sie finden nicht, was Sie suchen? Fragen Sie die Community oder teilen Sie Ihr Wissen mit anderen.