Hi there @stevebaer, @scottd, and @kike!! It has been a few moments since we covered this topic at the last TT AEC, but I finally got around to trying to automate silent loading of a GH script with a HumanUI using the methods we talked about. Will document my attempts here and I’m hoping we can get something to work so people can build slick apps on top of Rhino/GH with killer UX.
So… I’ve been playing around with the Rhinoscript interface for Grasshopper and it looks like so far my hopes have been dashed on what I’d like to accomplish. To recap, here is the goal:
Create a Rhino Plugin that contains 1 command, which can be run via command line or via a button in an RUI toolbar
The command launches Grasshopper (with absolutely no visible evidence of Grasshopper) and opens a Grasshopper script with a HumanUI interface (again, without triggering any visible instance of Grasshopper)
The script nonetheless executes when operating the HumanUI (this is the hard part, as we will see), despite there being no GH window
I’ve noticed several problems with the methods in the API, with respect to what I’d like to accomplish:
DisableBanner(): This is great and a welcome method – however, I would like to also be able to enable silent loading (no echo in the Rhino Command Line). Even better (amazing, actually) would be providing an overload that would allow me to define my own custom splash screen (Waaaaaaat!)
LoadEditor(): Again, love that the Load function is separate from the Show function, and simple tests show that it is possible o “Load” grasshopper without the window appearing. However, the behavior of other methods crushes the hopes and dreams that I had when looking at the documentation
OpenDocument(): And here’s where the tears start to flow. From the API docs: “Open a Grasshopper document. The editor will be loaded if necessary, but it will not be automatically shown.” Well in my case, using this method on a script that I have built with full HumanUI (no GH interaction necessary), regardless of whether I call LoadEditor() first, it does indeed automatically show the editor.
HideEditor(): There’s hope still! Perhaps if I hide the editor first, before opening the document! Nope, disappointment ensues. Okay, so maybe I’m disappointed that the Editor does in fact show during the load process, but I do have a script within my GH definition that automatically minimizes the editor so it’s not blocking my UI. At least I can use HideEditor() to get rid of that pesky GH window minimized at the bottom of the Rhino UI, right? A flicker of joy, as I successfully hide the GH window entirely – “this is it!!!” I think, and then deep sadness sets in as I push a button and nothing happens, as it appears that when the GH editor is hidden, it no longer functions (at least with my intensely insane script)
EnableSolver(): Perhaps I can enable the solver on a hidden GH instance! Nope.
Anyway, just thought I would do a dramatic retelling of my last 20 minutes for fun. H’s a sample of the code I’m using so you can point out any stupid mistakes I’m making:
Tried various combinations and orderings here. Main fixes would seem to include:
HideEditor(): Not disabling the GH execution context in this state (easier said than done?)
OpenDocument(): overload with a flag to prevent editor from showing automatically, or fixing the bug that does force it to show, or document in which cases it will automatically show, etc – also good compromise would be the ability to load in minimized state (never seeing the full GH window), a function not currently provided by the API (and would get me almost all the way to my goal)
DisableBanner(): overload that allows silent load (no Rhino command line echo)
In personal projects, I use Harmony as a workaround to hook window-related functions (System.Windows.Forms and now Eto) to prevent Grasshopper from being shown. Generally, it’s a complicated procedure.
HideEditor doesn’t hide the editor alone, it also closes the window, that’s what may prevent the execution context. Maybe try Visible = false?
As for Human UI, I forget whether Human UI uses GH or Rhino as its parent window. If its parent is GH, you would need more adjustments.
Interesting, I’d love to see a project where you’ve accomplished that, if you don’t mind sharing.
Yes, indeed “Hide” appears to simply close the window. Regarding Visible = false – the RS interface doesn’t implement Property accessors directly, AFAICT, only methods, and I am inferring that “Visible” in this context refers to whether the window is Hidden or not.
HumanUI can be set to Always on Top, or to use GH or Rhino as a parent (I usually tend to use the latter, so WPF parent relationships shouldn’t be an issue if I muck with GH)…
All that said, I would hope that a few strategic tweaks to the provided Interface could solve these challenges without having to dig in at Harmony’s level…
I am using a macro like this:
_NoEcho
-_Grasshopper
: Banner
: Disable
-_Grasshopper _Document
: Close
: Enter
-_Grasshopper _Document _Open “C:.****.gh”
: Enter
@taraskydon ~ This looks like what I am looking for. I would be grateful if you could share the exact code under the Pave and Hinge buttons on your toolbar. It also looks like you have some functionality built into the .gh to make this work. If true, could you share just that bit as well. I am unfamiliar with what I am seeing in the second image.
Thank you.
-_GrasshopperPlayer
not what i want. it works in a stealth mode and it is not possible to modify the algorithm in real time.
but I probably didn’t understand.
Thanks for this - I got it working well now. As you say, it is not perfect but it does work.
There was a quirk when I copy and pasted your button code. Your quotation marks did not work on my machine. I had to retype the quotation marks to get the command to run without wanting to browse for the file. Odd that…
There’s several kinds of quotation marks. Programming always requires the straight ones, regular typography prefers the angle ones. Since the script wasn’t placed inside a code block, Discourse probably replaced the correct marks with visually pleasing ones.