Prevent modeless form from crashing

34 views
Skip to first unread message

Coen Claus

unread,
Feb 1, 2019, 2:47:54 AM2/1/19
to RevitPythonShell

Goodday.

With the help from you all I managed to make a modeless form application which allows Revit to be active and my tool simulteanously.
However when the user clicks another button from my add-in it causes the following Error. (See attached image).

I can work around this using the the form.ShowDialog(). However that causes Revit not to be active.

Is there a way to prevent these errors showing up?


My code

form = AssemblyFilter()
external_event
= ExternalEvent.Create(form)
Application.Run(form)


The tool I am working on so far:







 
form showdialog.png

Daren Thomas

unread,
Feb 1, 2019, 6:02:05 AM2/1/19
to revitpyt...@googlegroups.com
Dear Coen,

The problem is with the line "Application.Run(form)" - that effectively creates a new event loop, the part of a windows program that gets OS level events (mouse movements, keys pressed and released, shutdown events and a whole list of other stuff that can happen) and processes them. Revit itself, as the host application, does this. You should be using something like "form.Show()" instead.

Best,
Daren

--
You received this message because you are subscribed to the Google Groups "RevitPythonShell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to revitpythonshe...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Coen Claus

unread,
Feb 6, 2019, 4:32:33 AM2/6/19
to RevitPythonShell
Thanks Daren for your answer,

I thought maybe a workaround for Revit to be active while the add-In is runninng can be the following:
Do you think it is a smart idea to disable the buttons on the Add-Ins Ribbon so the user can still select elements in the Active View But can't press the buttons to prevent creating new event loops.

That brings me to another question, I don't know how to disable the buttons on the Ribbon.

I guess I need the following, but I don't know how to find specific buttons to disable. I know form.showDialog() just block the entire Ribbon.

But maybe I can also use this:

Autodesk.Revit.UI.RibbonButton.Enabled

Anyway, now I'm rambling.

Daren Thomas

unread,
Feb 6, 2019, 5:05:53 AM2/6/19
to revitpyt...@googlegroups.com
I'm not really sure what you're trying to achieve... "prevent creating new event loops", there is only one event loop per Windows application...

Coen Claus

unread,
Feb 6, 2019, 9:52:02 AM2/6/19
to RevitPythonShell
My apologies, still learning. 

Let me rephrase the question.

I am accessing:

Autodesk.Revit.UI.RibbonButton.Enabled



Enabled needs a get and set Parameter according to RevitAPIDocs



There are examples given in C# and Visual Basic. But I have no experience with these languages and don't know how to translate it to Python...


Daren Thomas

unread,
Feb 6, 2019, 10:52:34 AM2/6/19
to revitpyt...@googlegroups.com
I think you should just be able to set the `Enabled` property of the RibbonButton (you have an instance of one of those, right?) to `True`.

Reply all
Reply to author
Forward
0 new messages