Open the file below and make sure you have Grasshopper covering only a third of the screen or have grasshopper running on a separate screen.
Press the button and a input window will appear in the center of the Rhino window asking for string input. If you press ok, the input window closes and the Grasshopper button stays in it’s True position as if it’s being pushed in. Like this:
It only returns to the default position again when you hover over the grasshopper window with your mouse.
This is causing issues in one of my other files. Is there a way to make sure the button automatically returns to it’s default state without having to hover over Grasshopper? Or alternatively, is there a way to make sure this window pops up on top of the grasshopper window? So that Grasshopper detects my mouse hovering over it after that window closes and the button therefore turns to the default state.
190415 Button problem.gh (6.6 KB)
In my experience, buttons and GHPython scripting components don’t play too well. Typically because a button click will expire the component twice (on click and on release i.e. a quick on/off or vice versa), but also that it might hang the component (say if you use it to capture a viewport to a file etc). My general workaround is to use a boolean toggle instead (which acts as a single-click radio-button when published to the RCP). Though that probably won’t help you much.
As there a good reason to not just pass the string as a normal GHPython input parameter (from i.e. a panel or a string param)?
Thanks for your sharing your experience @AndersDeleuran.
The button is for exporting and the grasshopper definition is for a client that normally doesn’t work with grasshopper. I’d like to keep it as simple as possible for the end user and therefore would prefer to use a button instead of a toggle. With a button you also just need to click 1 time instead of 4 times with a toggle to achieve the same result.
Ah yes, that is a good reason. It probably is possibly I imagine, perhaps by getting the name/GUID of the button canvas object, and expiring it after getting the string could work.
How do I find the list of components currently in use in the canvas?
In GHPython you can iterate over
Alright, I tried a bit to solve this half a year ago until I got overloaded with work and just ignored the problem. Today I tried having a stab at this again with no luck so far. Any further direction to point me in? ExpireSolution doesn’t seem to work, or I’m doing something wrong here.
191008 Button problem.gh
Alternatively, is there a way to make sure the pop up window activated from python always pops up in front of the grasshopper window? @DavidRutten @piac
That way the mouse will always hover over the grasshopper window after the popup is removed and thus deactivating the button.
if not x:
rs.StringBox("Press ok","this is a test","Test")
Interesting and simple solution. But it seems like the window then pops up every time the solution gets recomputed which is a problem.