Grasshopper

algorithmic modeling for Rhino

Hi, I checked to see if there was any discussion on the pros/cons of each of these, but couldn't find much.

I'm about to start learning one of these in order to do scripted components in Grasshopper. I already use Rhinoscript, so VB would be the easiest syntax transition. I also use Processing, which would mean C# isn't that hard to get into (I'm guessing?). However, I've been reading about the new developments with RhinoCommon and the new Python Scripting language and wondering if it would be a wise choice to learn this for Grasshopper as well?

The Python for Grasshopper is a separate plugin at the moment, which seems a little dubious (and difficult to share with people). Is Python likely to be more permanently incorporated into Grasshopper soon? Are there disadvantages to the current plugin; is the performance slower than the C#/VB equivalent?

The other question is documentation. VB.Net for GH seems to be the most well-documented, although there is now the Python Primer, which I guess applies to GH without too much difficulty?

Thank you!

Steven

Views: 4038

Replies to This Discussion

Hi Steven,

 

If you have no prior experience in C# or VB.Net I would recommend learning Rhino Python. The Syntax is much simpler. You will probably get to good results more quickly.

 

Python uses Rhino Common - just like C#. But Rhino Python has a "Scripting Language Wrapper" which breaks commonly used taks down to simpler functions.

Here's a general Example:

Take a look at the code on this website http://wiki.mcneel.com/developer/rhinocommonsamples/addline). Generally it's Rhino Common code in three language to create a line. They look equally difficult.

But if you use Rhino Python Scripting you can use an simplified syntax to get the same result. It's very similar to Rhino Script.

The code would be:

import rhinoscriptsyntax as rs

start_point = rs.GetPoint("Get start point")
end_point = rs.GetPoint("Get end point")

line_id = rs.AddLine(start_point, end_point)

 

OK - No Error Tracking here, but still you can see that the syntax is much simpler. (And in the end you just have less lines of code you have to debug.

And the good thing about Rhino Python is, that you can mix these approaches. Once you reach a level where Rhino Python Script doesn't get you there, which by the way happens very rarely, you can still use the Rhino Common methods.

Also, in Python Sycripting 99% of what you probably would like to do is available as a "wrapped" script function.

Rhino Python Script is currently also better documented than Rhino Common for C# and VB.Net. If you have used Rhino VB Script before, these functions will be very familar to you.

I'm not sure, why it's currently a separate plug-in. I belive the reason is that Rhino 4 (which is supported by GH) doesn't support Rhino Python. Also it's currently WIP, so it needed to be updated more frequently than GH itself. In the long run (I believe) it might be integrated into GH as a general component

 

- Martin

P.S.: To use Rhino Python within GH is a little more tricky than my example - but nothing compared to developing C#

P.S.2 Here's the code with Error Tracking:

import rhinoscriptsyntax as rs

def AddLine():

    start_point = rs.GetPoint("Get start point")
    
    if start_point is None:
        print "No start point was selected"
        return
    
    end_point = rs.GetPoint("Get end point")
    
    if end_point is None:
        print "No end point was selected"
        return
    
    line_id = rs.AddLine(start_point, end_point)
    
    return line_id

AddLine()

 

A word on performance

The performance of Rhino Python Script is worse than C# and VB.Net, since the Scriptsyntax slows the process down a little. It just executes more code in the background (that was already written and debugged for you).

It's a matter of how important performance is to you. If you use the Rhino Common Syntax instead of the Rhino Python Script Syntax within a python component, the performance will be almost the same as with C# of VB.Net

- Martin

A bit more specifically described, Python is actually also slower in purely-Python written numerical computations because it is interpreted, as opposed to C# and Vb.Net, which are JIT compiled. But if you use libraries such as NumPy, then this disadvantage pretty much disappears.

- Giulio
_________________
giulio@mcneel.com

Thanks guys! That gives me something to think about :D

Steven

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service