Revit Architecture Forum
Welcome to Autodesk’s Revit Architecture Forums. Share your knowledge, ask questions, and explore popular Revit Architecture topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problems with External Event in modeless form

1 REPLY 1
Reply
Message 1 of 2
Anonymous
239 Views, 1 Reply

Problems with External Event in modeless form

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(); } }

 

 

1 REPLY 1
Message 2 of 2
Anonymous
in reply to: Anonymous

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report