Is it possible to have a py script always running?


Simple example: Let’s say I have one polyline and each time I change it the script will create an offset of it.

Almost as grasshopper does it, but I don’t want to do it with gh, I want to have a pyscript always running in the background - so I won’t have to run it each time I change the polyline (it will always be running and offsetting live)

Is it possible? this could be useful for other things also.

Thank you!

No, it is not possible as far as I know. You cannot execute any other commands while a script is running.

Hmm, if I have the Properties panel open and I rotate the camera, the XYZ positions update in real time in that panel.
How is this done?

Sure, things like that are possible in the core code - but not with scripts which are running like non-nestable Rhino commands.

So conceptually, could it be possible to have a part of the core code dedicated to calling scripts?

(in this way scripts will be executed live on top of other commands, and will make things easier for users that want to create their own tools)

Not a programmer… It’s probably possible to make a C++ plug-in that does that, but that’s out of my league. However, it would be possible to script the polyline creation and auto-offset at the same time - as long as you were willing to use a different command than ! _Polyline to make the polyline itself.

You would of course have to deal with all the fun stuff that comes with offsets, namely which side to offset and various failure situations…

It’s not about the polyline, that was just an example. I’m talking in general for any script.

C++ plug-in that does that - this would be interesting!

It is possible. You’ll need to start your script in another thread, offsetting the curve and the hard part adding it to the Rhinodocument without crashing your Rhino instance. You also loose the reference to your thread once the script finishes. Therefore you need to store relevant references in the RH-Global sticky dictionary.

Hi @TomTom,

Do you have an example of something simple? (I thought offsetting was a simple thing, why is it hard?)


it is hard, because it is asynchron programming. Even an experienced programmer will have difiiculties with it. There is so much to think about, such as not running into a racing condition etc.
I’m currently not on a computer with Rhino installed, but as a first step you could read more about asynchron programming in (Iron)Python.

1 Like

Ok, so if it’s that hard It’s clear that it’s not suitable for users…
Is there any other way to do it? As @Helvetosaur was mentioning above, to have a plugin that will call the scripts.
The plugin itself should be done in asynchronous programming i guess, but the scripts done by users will be done in simple py…

You don’t understand, what you described is asynchron. So it requires asynchron programming… This might be simpler from a non scripting environment, but it still requires advanced coding skills :slight_smile:

OK, I bow to a higher authority…

It’s not possible for mere mortals like myself… :stuck_out_tongue_winking_eye:

1 Like

Ok, let’s simplify the problem then:

If i would like to have a panel that constantly tells me how many control points the polyline has. without adding anything to the document.
Is this more easy?

You could listen to events that Rhino emits. For example, Rhino should emit an event when an object has changed. When that happens (the case of your polyline changing), you can check the ID of your polyline and act accordingly. Here is a C# example that shows how to subscribe to a bunch of different kinds of events:
I think when you change the polyline, this gets called:

1 Like

well, you are right as well. Eventhough it is possible, it is something you shouldn’t do on scripting level unless you know what you are doing. So saying no is the better answer. And for those who know about, they simply don’t do these things in a scripting context… :slightly_smiling_face:

just that listing to events is a nono on a scripting level and it becomes really hacky to unregister properly. If someone is not knowing much about it, this person will very likely run into very odd and hard to debug behaviour.


thinking about something less complicated: you can basicly implement all this in a while loop in python, where you first enter your points outside of the while loop, then create the polyline and offset inside the loop. since you are always refering to guids you should be able to modify the points and thus the polyline.

@rgr yes, I understand your point. but then the only thing i will be able to do is to play with the polyline :slight_smile:

(the polyline was just an example to illustrate the problem, what i truly want is to have any other thing running on top. but i do understand that it is complicated)