[Solved] [Question] Rhino.Python API

It’s probably me, but how come the simplest example taken from the API doesn’t work.

PY_hell

2018-05-29%2021_28_30-Rhinoceros%206%20Commercial%20-%20%5BPerspective%5D

What is that Prompt supposed to do?

Where can I find examples where user can click on the parameters on an active command to enter values instead of being prompted each value separately?

Have a look at this example: ( click the python tab for the example)

-Willem

1 Like

Thanks Willem.

Under the RhinoCommon examples. Never would’ve guessed that.
When I read RhinoCommon I get the C#/VisualStudio image in my head.

Python in Rhino is IronPython is .NET, thus RhinoCommon.

Yes, I know that IronPython is .NET. Just it’s a bit confusing here: http://developer.rhino3d.com/api/
http://developer.rhino3d.com/samples/

I thought RhinoCommon is more for compiling RhinoPlugins and GH components. That’s why I didn’t look inside RhinoCommon for scripting purposes.

Does it mean that I can use Python inside VisualStudio to compile RH plugins and GH components?

IronPython yes. Or any other .NET language for that matter. I like F#.

Hi all,

DLR (Dynamic Language Runtime) languages in .Net are a little special, actually. We had to add some special binding to load IronPython-based Grasshopper assemblies, and Rhino commands also have a special system to be found. Both already exist, though, and are supported in Rhino 6.

To be back on the topic:

Why doesn’t this do anything?
import rhinoscriptsyntax as rs
rs.Prompt("Hello Rhino!")

Hi @ivelin.peychev,

When run from the editor, the code really doesn’t do anything because the editor itself changes the prompt when running scripts.

If all you want to do is print something to the Rhino command line, just use Print.

– Dale

Hi Dale,

How else can I run it?

Does Print and Prompt the same? I firtst I thought Prompt was like a pop-up gui message.
I saw I can also print in the status bar.

Save your code to a .py and then use the RunPythonScript.

– Dale

Thanks @dale,

I still don’t see Prompt doing anything.

py%20-%20Notepad%20

2018-05-30%2001_36_17-Rhinoceros%206%20Commercial

Hi Ivelin,

I think the prompt is very soon overwritten and you cannot see it.

Something like this gives us a little more time .

import rhinoscriptsyntax as rs

for n in range( 999 ):
    rs.Prompt( str( n ) )

Regards

How can it be overwritten, this is why I am using different string for Prompt and print?

AFAIK, the prompt is what you see temporarily, until a print (or another prompt) overwrites it.
The prompt text is not saved in the history, it is only shown to the user until something else is shown there.

It indeed works for the duration of your script/command.

or this:

import rhinoscriptsyntax as rs
for n in range(10,0,-1):
    rs.Prompt("Countdown: {}".format(n))
    rs.Sleep(1000)
rs.Prompt("Go!")
rs.Sleep(1000)
1 Like

Your script is setting the prompt. But when the script ends, the prompt is reset. All this happens so quickly you can’t tell anything is going on.

Here is (another) sample that might demonstrate its purpose:

import rhinoscriptsyntax as rs
for n in range(0, 100):
    rs.Prompt('Calculating (' + str(n) + '%)')
    rs.Sleep(50)

– Dale

1 Like

Thanks everyone,

I’m a bit pre-occupied at the moment, I’ll definitely check what you proposed.

Regards