I have received this C# script from Andrew Heumann if I remember correctly…
The script can be used to manipulate a slider with F7/F8 on the keyboard or by setting F7/F8 to buttons on a 3D Connexion Space Navigator or even on a Wacom Intuos tablet with buttons or the touch wheel. The slider is linked to the script with Metahopper.
The script worked fine in the original grasshopper file.
It also worked fine in any other file I copied it into, until two days ago when I updated Rhino.
ahhh nvm @DavidRutten I see that saved old scripts automatically migrate their old usings (you think of everything!). @martinsiegrist - did you copy-paste this script from somewhere, rather than opening from an old file?
Yep, a severe error on my part. If a script component is loaded from an old file is runs fine, but if it is saved without being modified (even trivial modifications will do) it will not load fine again. This was missed during testing because it requires a file to be opened twice before it breaks, still … very amateurish.
This file contains a script component which will repair the missing references in a GH file (it will save another file next to it with the fixes). However this file too will fail to load a second time because of the exact same reason.
To fix a file permanently, run the attached script, then open up each script component and add a blank line somewhere. Apologies for this mess, it has been fixed, but that fix will take some time to get out to everyone.
While at it, why not add the methods private virtual void PreCompile() and private virtual void PostCompile() to the Script_Instance as well, so we have a place to manage eventhandlers before they become inaccessible due to compiling…
… OK I see what you mean. Any such methods in the Script_Instance would still always be the previously compiled currently running version.
For the purposes I was thinking of, namely a chance to unsubscribe event handlers if any, a solution that could work could be to have an extra eventhandler “OnJustBeforeImDying()” fireing just before the destructor is done with the object that is about to be recompiled. Perfect would be if such an event could be fired by GH_Component’s destructor, and of course, also unregistering any hooks to itself before entering eternity.
There’s that problem with eventhandlers (Mouse & Kbd events) not being unhooked before the script component is recompiled, and so they’re still firing in their “after life” so to speak. (Yes, there obviously is an afterlife). Any solution should compile also in VS.
Sorry for highjacking the thread, but this problem really should be solved. We need event handlers for Mouse & Kbd events but they’re currently causing problems in script components.