I am working on a custom Grasshopper plugin to work with Rhino.Inside.Revit that makes a series of operations on a Revit model. InvokeInHostContext() is used for Revit transactions avoid conflicting API resources in a few key Revit API methods I am using as advised in this thread. I am also using File3dm to access objects in external documents.
When I execute my Grasshopper component:
- The code executes as expected
- Revit transactions are completed without error on the model and I can see the desired result
- The component’s output data is set as expected
- I can edit and work in the Revit model as normal after the code executes
However, upon completion of the code, the Grasshopper UI navigation and editing is ‘broken’:
- I cannot select or edit canvas elements
- I cannot pan on the canvas
- I cannot interact with UI elements - such as sliders or toggles
- I CAN zoom in and out of the canvas
- I CAN hover over inputs and outputs and see preview of the data
- Menus appear operational
Closing and re-opening Grasshopper within Revit does not seem to resolve the UI issue. It does seem that I can open up the Rhino interface but Grasshopper remains locked up. Only a complete Revit restart restores UI features in Grasshopper.
So it appears that Grasshopper was hanging because the File3dm object - used for reading an external 3dm file - was not being Disposed. This was solved by calling the File3dm.Dispose() method. Grasshopper appears to have returned to a normal state after calling this.
I take that back - the issue seems more inconsistent - sometimes full control over Grasshopper UI is returned after executing my definition, other times, only partial control of the UI (as described above) is returned. I haven’t pinpointed the issue but it doesn’t seem that Disposing of the File3dm resources was the fix I was looking for.
Are there known cases that result in partial breaking of Grasshopper UI control within the Rhino.Inside.Revit context?
Okay so it seems my issue was… a BUTTON!
@andheum kindly pointed out that Grasshopper buttons may be causing the interface to partially lock up. Sure enough, once I swapped it out for a Boolean Toggle, my Rhino.Inside definition is moving along as expected.
If you REALLY, really want a button this in a C# component will make it run on the Button-Up event:
private void RunScript(bool select, ref object A)
// Get around the canvas freez thing: https://www.grasshopper3d.com/forum/topics/boolean-button-runscript?commentId=2985220%3AComment%3A1812802
if(!select && !pending) //return when button isn't pressed
// Code to run on False, if any
if(!pending) //return & set pending to true
pending = true;
pending = false; // reset pending to false
// Code to run on button up-event.
// <Custom additional code>
private bool pending = false;
// </Custom additional code>