Prevent Revit from receiving a delete command in API modeless form

Prevent Revit from receiving a delete command in API modeless form

joshua.lumley
Advocate Advocate
545 Views
1 Reply
Message 1 of 2

Prevent Revit from receiving a delete command in API modeless form

joshua.lumley
Advocate
Advocate

I am desperately trying to prevent revit from receiving a delete command while in a modeless form (one that was displayed with Show() and not Showdialog()), but I can’t seem to be able to stop it.

 

My problem is my form contains textboxes: its core function requires the user to be able to navigate (pan and zoom) in revit without having to close and reopen the form.

 

But as soon as the user presses delete on any textbox text revit thinks the user has entered a delete command in the main window, and this could lead to accidental deletions.

 

Note the api queries a revitdb based on selected entities (families) and is then they are able to rename the family type or family name, using a textbox and ‘apply’ button. But as soon as they hit the delete button on the keyboard, guess what – the entity is deleted in revit.

 

I’ve  spend 10 hours on this and it could turn out to be catastrophic to my plans.

 

Kind regards, 

Joshua Lumley

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

FAIR59
Advisor
Advisor

Presuming you are communicating with Revit via External Events, you can create a new thread to display your form. Then the message functions of your form are separated from the Revit application.

 

Define a new class

 

  public class NewFormThread

    {

        // This method that will be called when the thread is started

       public void Execute()

       {

          Your_Form form = new Your_Form();

          form.ShowDialog();

       }

    }

 

In your code replace the call to show the form [form.Show()] with:

 

  NewFormThread _newFormThread = new NewFormThread();

     // Create the thread object, passing in the Execute method

     // via a ThreadStart delegate. This does not start the thread.

  Thread oThread = new Thread(new ThreadStart(_newFormThread.Execute));

     // Start the thread

  oThread.Start();

 

0 Likes