Cancel running command

Cancel running command

carolina.machado
Advocate Advocate
1,568 Views
2 Replies
Message 1 of 3

Cancel running command

carolina.machado
Advocate
Advocate

Hello everybody,

 

Do you know if there is a way to monitor the ESC key to stop an external command execution? Or any other way to do so? I have some commands that takes a long time and I want to enable the users to Cancel the running if they get tired of waiting.

 

Thanks in advance!

0 Likes
1,569 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni

Long duration built-in Revit commands display a progress bar and regularly raise the ProgressChanged event, enabling cancelling the process::

   

https://www.revitapidocs.com/2024/cabf8932-111c-6036-3d74-3d33c18260ed.htm

    

Inside your own code, if you are in a loop, you can throw an exception, e.g., OperationCancelled. That should normally terminate the external command. If you wish, you can try to catch it an to display a more graceful message than the normal Revit error report.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 3

carolina.machado
Advocate
Advocate

Thank you, @jeremy_tammik . My goal was to enable user to stop an external command though.

I searched a bit more and found this: https://jeremytammik.github.io/tbc/a/1281_progress_animated_gif.htm which led me to this: https://github.com/lotusinriver/MonitorProgressRevit

I think I'll try implement it in my code. Do you know if it stopped working for newer versions of Revit?

0 Likes