RunScript vs RunPythonScript inside commands problem

Hi @stevebaer,

Since you were the one fixing with how RhinoScript / RunScript works and make sure it works inside Rhino commands, I figured I would ask you again since I have ran into similar issue with RunPythonScript. The issue is RhinoScripts work fine when run from button or compiled plugin inside other commands but Python scripts don’t.

Take a sample button like this:

Both work just fine when ran from a button on their own (no other commands running)

However, when, for example I start drawing a Polyline and run the RhinoScript one, all works fine: script prints to command line and then we can continue to draw; Python version fails: command line looks like this:

Unknown command: (

print("Python 1")
print("Python 2")
print("Python 3")

)

Would it be possible to make the RunPythonScript command work as well as the RunScript one, and let us run Python scripts inside other commands (as a fix in Rhino 6 SR…) ?

thank you,

–jarek

Hi @Jarek,

The command line argument to the scripted version of RunPythonScript is a path to a script file, not the actual script code to interpret. So, RunPythonScript is analogous to the LoadScript command, not RunScript. But I understand what you are asking.

https://mcneel.myjetbrains.com/youtrack/issue/RH-56354

– Dale

1 Like

Hi @Dale,

Thanks for adding this to the list. I am a bit confused though, since I can run the python code in parenthesis, even multi-line one from buttons, macro or even from within a RhinoScript code. The issue is it fails while ran inside other Rhino commands (unlike RunScript command). So maybe it takes both filepath AND the code? Still learning my ways around Python but having it work inside command would be critical to start migrating some of our tools into Python/RhinoCommon.

thanks again,

–jarek

I could not find this documented in Help file, but at least on Windows version, this works (per @Helvetosaur detailed post). But NOT if inside a running command :frowning:

To run a python script (.py) from a toolbar button:*
Right-click in a blank space in any toolbar and choose “New Button”.
In the button editor that opens, in the "Command area, type the following:

! _-RunPythonScript (

<paste the entire script here>

)

Then OK to exit the button editor. When you click the button, the script should run. Make sure to save your workspace file.

Yeah, I don’t think that has ever worked. I think the RunPythonScript procedure is probably hard-coded to cancel any running command first… I have no idea what the dangers might be to allowing a script to run inside a Rhino command might be.

Hi Mitch, I am not aware of any dangers since I’ve been doing this forever with RhinoScript (via buttons and compiled plugins) and saw only advantages, no dangers. I hope it is just a way how this is passed to the command line and parsed that could be tweaked, so we can run Python scripts inside commands the same way as we do with RhinoScripts now. It is really really helpful in many situations to be able to do so.

–jarek

I’m all for it… But I have no idea what’s involved.

1 Like

Great. Here is one example that I just posted in another thread - realtime view stretching via script. Since it is using some Python, it would not work while, say, drawing a Polyline, which would be handy if this was fixed:

It looks like there is just a difference how the command line of -RunScript and -RunPythonScript behave once in command. RunScript pauses for user input ( body of code or filepath ), vs RunPythonScript just “gives up” while in command (quits before code body or path are provided). If this could be fixed, the behavior would be consistent and we could take advantage of Python scripts while in-commands. Hope this is tweakable!

–jarek