I’ve got some scripts I made in Grasshopper that I would like to convert to Python/ETO forms so as to be more user friendly for people who may not be familiar with Grasshopper.
I’ve run into a problem, which is that while I can, say, scale a circle by selecting its radius with a dropdown, if I try to do that with a slider, Rhino crashes.
Is there some way to make changes to geometry with an ETO slider without crashing Rhino?
I want to do fairly complicated things (for example, build some sweep surfaces that update as the slider is moved), but I have created this simple example that simply scales a circle, and I can’t get it to work.
NOTE: the script needs to run under python2 to be compatible with Rhino6 and Rhino7 if at all possible.
I am mobile and can’t look at your .py right now but you can achieve a sweep with the following logic. Use the Extend Curve component with a remap value and slider where the slider is 0-1 or 0-100 or whatever and then the domain of the curve is 0 to the max curve length you want for your path.
The slider then remaps to the curve domain where 100 or full slider would be the full curve length and 0 slider value would be a 0 curve length.
This allows you to use the slider to parametrically extend or shorten the curve which would, in turn, extend or shorten the overall swept geometry while keeping the original, intended sweep path/rail.
TLDR:
Remap a Sliderto the curve Domainof your Sweep rail input
That’s an interesting idea, which I had not considered, but it would be something new for me to learn and it wouldn’t match the look and feel of the rest of my toolset. Also, I’m not sure about this, but it looks like people who use my tools would also have to download and install Human UI? If so, I’m trying to avoid things like that, but I do like the general idea of it. It does look like something I should look into.
Thanks for the suggestion. First, though, I needed to get past Rhino crashing the moment I move the slider. Nathan’s provided code does the trick. And I also discovered that if I update on the slider’s MouseUp event, that also works (basically nothing happens until you release the mouse…so it’s not as fluid as it should be, but it works).
Once I pick a method, I can get into the nuts-and-bolts of building/updating the objects. The first tool I’m working on will involved resizing closed curves, so your idea won’t apply, but I think one of my other tools will be using open curvers…I’m not sure how I’m gonna handle it yet, but your suggestion would possibly apply there.
Nathan,
I had another problem, which was that OnMouseUp and OnMouseDown on the slider would sometimes crash the script (but not rhino). The script only crashed when the event happened over the tick marks (if the event happened over the slider knob, it was fine). The error was that OnMouseDown required three arguments but only two were given (or something like that). Researching that led me to your answer here (from another thread).
Turns out just renaming my handler to something other than OnValueChanged prevents the original crashing problem with the valuechanged event. My original code seems to work fine now that I’ve renamed the event handler.
I noticed that your scripts starts with # python 2. if you intend to run this with python 2 and not 3, make sure the lines starts with #! as in #! python 2
The original script you shared is being executed by python 3 and since it is python 3, you would need to make an explicit call to the initializer of the base dotnet class:
The script editor complains about this missing call in the Problems panel:
Thank you! I haven’t been able to use the Rhino8 editor because of this. I could code in it, but it wouldn’t run any of my projects. The error I always got was “Object reference not set to an instance of an object.” I frankly gave up on it and did most of my coding in Rhino 6 or Rhino 7.
The only way I could test my code in Rhino8 was to make an alias for it. I couldn’t even use the Tools > Script > Run anymore (that used to work for me).
But this fixed it. I had tried adding the super().__init__() before but maybe I added it in wrong or maybe it was the missing ! in the python2 comment…I don’t know, but I can run my projects in the Rhino8 editor now.
You would need super().__init__() in Python 3 only. The reason being python 3 does not automatically call any of the base initializer (constructors in C#). So if you derive from a dotnet type, you’d need to call the base initializer explicitly. Most classes have multiple initializers so it is important for the deriving class to choose which to run with.
The Error messages in Problems panel are your friend
Well, I got something working sort of, but it’s kind of lame. So, here I am watching human ui tutorials…gonna try to learn the basics and see if it will do what I want.
Edit:
Welp, HumanUI is not cross-platform. And synapse – another of your suggestions on another thread – seems under-developed…or i just don’t know how to use it. Like I can’t figure out how to adjust padding and spacing on a form in synapse.
Edit2:
Okay, I’ve figured out padding in synapse…so I’ll keep looking into that.
Edit3:
I made a simple form with a label and slider that makes a circle and lets you set the radius, and it works really nicely and I like the standard ETO form look, but, unfortunately the user has to open grasshopper anyway and it also looks like they have to toggle the form to show…and I think they will also have to install the synapse GH plugin…for all that, I might as well teach people how to use my grasshopper definitions. I really want them to click on a toolbar icon and just get the ETO form and never even see GH. I want GH to run completely in the background and be driven by the ETO form. I’m not sure that’s even possible (tho it looks like HumanUI does that somehow). I’m guessing I would need to create my own specific GH plugin, which I don’t know how to do at the moment.
What I’ll probably do is drop the idea of having sliders on my ETO forms and just give the users textboxes to enter the numbers in…it’s disappointing and not as cool, but I think it will get the job done…and even that may take me a while.