[Solved] [Question] Rhino.Python API


(IVELIN PEYCHEV) #1

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?


(Willem Derks) #2

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

-Willem


(IVELIN PEYCHEV) #3

Thanks Willem.

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


(Nathan 'jesterKing' Letwory) #4

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


(IVELIN PEYCHEV) #5

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?


(Nathan 'jesterKing' Letwory) #6

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


(Giulio Piacentino) #7

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.


(IVELIN PEYCHEV) #8

To be back on the topic:

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


(Dale Fugier) #9

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


(IVELIN PEYCHEV) #10

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.


(Dale Fugier) #11

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

– Dale


(IVELIN PEYCHEV) #12

Thanks @dale,

I still don’t see Prompt doing anything.

py%20-%20Notepad%20

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


#13

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


(IVELIN PEYCHEV) #14

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


#15

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.


(Nathan 'jesterKing' Letwory) #16

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


#17

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)

(Dale Fugier) #18

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


(IVELIN PEYCHEV) #19

Thanks everyone,

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

Regards