pyrevitlabs / pyRevit

Rapid Application Development (RAD) Environment for Autodesk Revit®
http://wiki.pyrevitlabs.io
GNU General Public License v3.0
1.24k stars 329 forks source link

How to do PostableCommand execution without closing Windows Form? pyrevit #2287

Closed RomanSanta closed 3 days ago

RomanSanta commented 4 weeks ago

I'm currently working on a custom Add-in for Revit with pyRevit. The Add-in runs a form created with Windows.Forms library with a button in it. When the button is pressed its supposed to take id of an object from project and appliy Selection Box command to it. I did everything right, but the problem is that the PostableCommand only executes if you close the form. Else if you press the button twice or more it just gives back an error saying 'Revit does not support more than command are posted'. If I get it right, you cannot run a command and form together at one time. Anyways, I'm sure there is some way to avoid it. On the internet I found solutions like: -subscribing to Idling to see if Revit is busy with some command at the moment -some 'Invoking' methods. (Didnot get how it works) -closing the current form and creating a new one (the closest one) maybe the last one is what I need. But how do I make Revit do the command in the span of time from closing original form and running a new one? (run the first form -> button pressed -> close the form -> execute command -> run the copy of the original form)

Big thanks to all who will answer!!

dosymep commented 4 weeks ago

This is not possible due to the way Windows works and the philosophy of PostableCommand (it is executed asynchronously, commands are written to the thread’s message queue and then executed; in Revit there can be a queue of at most one message). There is a workaround: open the window using Show.

RomanSanta commented 4 weeks ago

This is not possible due to the way Windows works and the philosophy of PostableCommand (it is executed asynchronously, commands are written to the thread’s message queue and then executed; in Revit there can be a queue of at most one message). There is a workaround: open the window using Show.

Oh thanks a lot I'll try it.

RomanSanta commented 4 weeks ago

If someone has any other solutions, please let me know anyway

sanzoghenzo commented 3 days ago

Im going to close this since it's not a bug nor a feature request. If you want to continue the conversation, please do so in the discourse forum. https://discourse.pyrevitlabs.io