Grasshopper

algorithmic modeling for Rhino

EDIT: This was the earliest release of the component. Now you can find the new more updated version here.

Hi all,

I've read this thread started by Benjamin and it made me look into integrating the new Rhino V5 Python interpreter into a Grasshopper component. After a couple attempts, it seems now to work well in V5. If you are eager to try again the Python syntax in Grasshopper, this should be useful.

This component will still need to be significantly improved with respect to features and performance, especially variable non-textual inputs, syntax editor and highlighting and parse-time error notifications would come in handy.


To install (the usual way), in Grasshopper 0.7:

  • download TestPython.gha
  • copy it to C:\Program Files\Rhinoceros 4.0\Plug-ins\Grasshopper\Components\
  • right-click the file, then chose "Unblock" inside the properties dialog
  • start Rhino v5 and load Grasshopper
  • for a simple example, you can try the definition above


I am also attaching the source code (in C#, TestPython.7z), in case you feel like having a look.

- Giulio
______________________
giulio@mcneel.com
McNeel Europe, Barcelona

Views: 3242

Replies are closed for this discussion.

Replies to This Discussion

Nice!
!!! Thank you Giulio!!!
Thank you Giulio ;)
Excellent!
Thanks man!

Evert
Hey, I just have have a quick question...


What version of GH are you using with this?


Thanks and great development!

Z
Hi Zach,

the project is referencing Grasshopper 0.7.57 and Rhino v5. It probably also works in earlier versions of 0.7, though.

- Giulio
________________
giulio@mcneel.com
McNeel Europe, Barcelona
Hi Giulio,

For some reason I needed to recompile the component for it to work.
I'm assumming the rinoscript methods are not available, are they?

How do you suply arguments?
Cheers

Evert
Hi Evert,

it's possibly due to something as simple as this (downloaded file block):

On English installations it reads: "Unblock". See here one example.

- Giulio
________________________
giulio@mcneel.com
McNeel Europe, Barcelona
... about the other questions: yes, RhinoScript is available. It's probably wise to only use it for analysis, selections, or seldom baking - as otherwise it will quickly fill the document.

E.g., selecting all objects on a given layer:
import rhinoscriptsyntax as rs

strObject = rs.GetObject("Pick an object to select layer")
if strObject != None:
  strLayer = rs.ObjectLayer(strObject)
  Py_Res = rs.ObjectsByLayer(strLayer, True)


Simple baking:
import rhinoscriptsyntax as rs
rs.AddPoint((0,0,5))


Supplying non-textual arguments is something on the list. For now, only textual input is possible.

- Giulio
________________________
giulio@mcneel.com
McNeel Europe, Barcelona
Hi Giulio,

Thanks for the explanation, I should've read the instructions thoroughly on the original post 8), I'll give it a go tonight when I get home.
As a matter of interest, if you create and delete objects with rhinoscript, does the memory becomes free when you delete them?.
Does the garbage collector kicks in with this component?
Cheers

Evert
Hi Evert,

yes, the .Net memory will be collected as usual. We have to be careful with the Undo-Redo stack of the Rhino document while we use RhinoScript, though. It always keeps track of the changes, therefore it increases slowly but steadily during any RhinoScript method that modifies the document.
So, if we write this:

RhinoScript
import math
import rhinoscriptsyntax as rs

ptList = [((math.cos(i*0.3),math.sin(i*0.3),i*0.3))for i in xrange(0,100)]
o = rs.AddPoints(ptList)
Py_Res = [rs.PointCoordinates(i) for i in o]
rs.DeleteObjects(o)


The undo-manager will keep track of the changes while we are inside of the script, while with the following the document will be untouched

RhinoCommon
import math
from Rhino.Geometry import Point3d

o = [Point3d(math.cos(i*0.3),math.sin(i*0.3),i*0.3) for i in xrange(0,100)]
Py_Res = o


- Giulio
________________________
giulio@mcneel.com
McNeel Europe, Barcelona
Great Giulio! Very handy!

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