Python Script Advice

I see there is rs.EnableRedraw(False) to suppress drawings while running a script, and that speeds things up tremendously.

Is there also something to suppress the output to the command history?

Hi @James_Richters,

Try this:

echo = False
rs.Command("_Unlock", echo)

– Dale

Hi @dale

That took care of most of it and did help quite a bit, but I still get messages from the commands, like

Exploded 2 instances into 18 objects.

any way to shut those off during the script?

Nope. Only way to avoid them is to use native rhinoscriptsyntax or RhinoCommon functions instead of calling rs.Command().

1 Like

It would be handy if I could search this list of commands for things that I don’t know what group they might be in. Most of what I need is in that list, but I don’t know where to find commands without expanding things one at a time.

It’s not always obvious, I looked around for a long time for something like SelLayer, and I of course was looking through LAYER… but it’s not there, it’s under Selection. I eventually did find it, but a search would have found it immediately.

searching online isn’t always reliable… I end up finding things for C that don’t seem to apply, or some other system.

Is there a simple searchable list of commands online somewhere so I can just see what category things are in and what is available? I tried just doing a google search for RhinoCommon and rhinoscriptsyntax and I get way too much information. or maybe a command reference for any command I could use in Python. I’ve been all over the place and I can’t seem to find a simple list of commands… other than the one inside the python editor, which is perfect, except isn’t searchable.

Use the online rhinoscriptsyntax help, it’s easier and searchable. Hit F1 when in the script editor.

Hi @James_Richters,

Rhino is made up of lots of commands. Here is the big list.

Rhino Help

For the most part, Rhino does not have APIs that mimic Rhino commands. Most commands are complicated, and it’s not possible to provide a single function that does what a command does.

That said, you can access the core functionality behind most command by using the RhinoCommon API. Here are the API classes/methods/properties available to Python users.

RhinoCommon API

In addition to this, there is rhinoscriptsyntax, which is intended to mirror our RhinoScript (VBScript) API. The intent of rhinoscriptsyntax is to assist developers who know legacy RhinoScript migrate to Python.

In fact, rhinoscriptsyntax is written using RhinoCommon. Here is the source code.

rhinoscriptsyntax on GitHub

There is aditional background on all this on our Developer site.

Rhino Developer

Hope this helps.

– Dale

@Helvetosaur Thank you, that gets a nice searchable list fast, Thanks!!

@dale Thank you for the links and explanations. I think when I just do a google search I am ending up with pages like this: ExtractSurface

I guess it is just RhinoScript, not rhinoscriptsyntax… I look at it a while… what is this ‘Dim’ all about? and then I think… wait a minute, this isn’t even python I am looking at here… there is no End If…

Doing a search directly in the Api reference is much more effective! Google searches are just useless.

Always surprises me why people would search through the entire internet via Google when just one document will do - and especially the one created specifically for the purpose.

@dale - maybe this page needs some updating?

:thinking:

The problem for me was finding the one document… it’s not easy if you don’t know what it’s called or where it is.
I have been programming since 1980 so I knew from the beginning I wanted a command reference guide. I got to this page on day 1: Rhino - Rhino.Python Guides (rhino3d.com)
and the very first thing I want to find was command reference guide… and I could not find them… and I STILL cannot find them on that page even though I know what they are called now. the closeest I come is this:

but that doesn’t get you to a command reference.
this also does not get you there:

and it’s not on this page either: Rhino - APIs Available to Python (rhino3d.com)

It would be GREAT it there was a huge section in BOLD like the others:

Python Command Reference Guides
Rhino - RhinoScriptSyntax (rhino3d.com)
RhinoCommon API

Then it’s obvious where to find them

1 Like

Is there a way to see what the Rhino commands are doing internally so that if you have a Rhino command that does almost what you want but not exactly, you could see what commands the Rhino command is doing and use that as a basis to create a script that does it in the custom way that you want, instead of starting from scratch and ending up mostly re-inventing the mostly same exact thing?

Well, for rhinoscripsyntax it’s considered a Help file - it used to be a .chm stored on your computer, but that’s old and didn’t work for Mac users, so now it’s online. So, as a Windows standard, it’s available from the Help menu or directly via F1 (same thing with the native Rhino online help).

Well, it is fairly clearly linked from here (Rhino - API References):

It’s also there under “Guides” but maybe not extremely well-placed.

Being someone who uses this stuff daily, I have shortcuts on my Windows start screen:

image

Unlikely. First Rhino is programmed in C++ and I’m not sure the source code for the individual commands is available, as that is a bit of their IP. What is available is on several levels:

First, actually running Rhino commands via rs.Command(). This gives you access to the high level sophisticated native Rhino command that has visual feedback and many bells and whistles.

Next, something like rhinoscriptsyntax - this is one step deeper into the entrails of Rhino, but still fairly easy to use and understand. However, as lower-level methods they will lack the multifunctionality of many native Rhino commands and generally lack an interactive onscreen preview. Rhinoscriptsyntax is actually just a set of ‘wrapper’ functions built around RhinoCommon, you can find them all here on your very own computer:

C:\Users\<username>\AppData\Roaming\McNeel\Rhinoceros\7.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript

Next in the ‘downward’ direction is RhinoCommon itself which is a set of OOP classes with methods and properties that allow you to access far more stuff than rhinoscriptsyntax. However, you need to know how to use OOP and the API Guides are not really intended for beginners. There’s a lot more involved in writing RhinoCommon code, but the possibilities are also much greater. You can also access RhinoCommon not only via Python, but also via C# and VB.Net.

Lastly it is possible to program stuff directly in C++ which is what I guess many of the sophisticated plug-in developers use. That is again a whole 'nother level down into the molecular structure of Rhino. Personally I have no clue about how to use that level.

2 Likes

that link brings you here:
Rhino - RhinoScriptSyntax in Python (rhino3d.com)

I don’t see how to get to this page from there
Rhino - RhinoScriptSyntax (rhino3d.com)

edit: I was looking at this link from here: Rhino - Rhino.Python Guides (rhino3d.com)

they both have the exact same text, but take you very different places

I also don’t see how to get to Rhino - API References (rhino3d.com)
from Rhino - Rhino.Python Guides (rhino3d.com)

Good idea, I think I will do that too.

I see it starts to get a bit complicated… I think I’ll stick to python for now, it’s suits my needs very nicely and I can always use the Rhino commands from inside python anyway. It makes no sense if writing the script take longer to figure out than the amount of time that would be saved by the script :slight_smile:

Yes, you’re right, my bad. As this stuff has developed somewhat haphazardly over the years, there are some holes in the crosslinking…

I think it would be great if this:

was directly on Rhino - Rhino.Python Guides (rhino3d.com)

There is even a place for it:


:smiley: