Why is Python still not as good as RhinoScript in this area?

Hello,

Very often we stumble into this weird limitation that did not exist for legacy RhinoScript: RunPythonScript scripts fail while running them inside already running Rhino command.
This is true both for a link to python script file, or python code inside parenthesis.

There are many scripts that make a lot of sense to use while inside commands like anything that deals with display mode changes, layer visibility etc. so in that case this is still a serious limitation.

RhinoScript does not have this limitation. Interestingly, if we compile Python script into a command with Rhino compiler, it also works fine and then can be run from inside other Rhino commands. Because of that I can’t imagine there would be any problem with fixing the RunPythonScript command issue. Could V8 SRx finally make it work please?

I think there is an old and dusty YT item for this: RunScript vs RunPythonScript inside commands problem : RH-56354 (myjetbrains.com)

–jarek

I currently have little time to implement an example, but its doable if you think a bit out of the box. You can start a „service“ by starting a piece of code which runs on a dedicated task/thread which observes either keys being pressed or by monitoring the command terminal. It then delegates a custom action. You‘ll likely need to invoke the actual logic within the main/ui thread. This is not as straightforward in IronPython, but its quite common technique when developing concurrent .Net apps. Still you need to be careful when implementing it from a scripting perspective. You need to terminate the service before you remove the reference, otherwise you have multiple and potentially different instances running. Better if this middleware is designed as a plugin. But sure, having a concurrent python command would be much easier

Hi Tom,

I can’t quite grasp your idea of the advanced way of dealing with it - it’s an interesting concept, yet still a workaround for something that should be quite simple and work intuitively. The easiest workaround is to compile the Python script into a plugin and then it works fine, just seems like it should not need to be that complicated. Let’s just have Python scripts ran by RunPythonScript command not cancel any running commands. I just found my old post with an example (back then I did not realize the compiled Python scripts would work so that was not reported back then). Maybe that update helps, seeing that there limitation like that is not needed.

@Jarek - sorry this has been rotting for so long. This should be fixed in a Rhino 8 SR9 release candidate coming soon.

– Dale

4 Likes

@Dale, great news, thank you! can’t wait to give it a try.

@Dale - I just tested it - works great, as expected. Thanks again.
Would it be possible to have it work in V7 as well, if there are any SRs still planned for it?
(We still do most of the work in V7, but more and more experimenting with finally transitioning to V8)

Hi @Jarek,

We are no longer making changes to V7, unless something catastrophic comes up.

– Dlae

Got it, thanks Dale.