Grasshopper tools in C#

Grasshopper features an impressive amount of highly interlinked components – from lines to trees, from circles to graph editors. Sometimes, however, when design tasks become more advanced, we might need to further customize this plugin by directly borrowing from Rhino commands. With these scripting components, the user can quickly solve otherwise more complex design behaviors.

This list of C# scripts is a work in progress and is open for requests. Supporting  v. 0.8.2 and some previous versions.

baking & Referencing
bakeName bakeName
GH 0.6.0012
GH 0.6.0018
GH 0.6.0043
obj (geom) – a list of objects to bake
name (string) – a list of names (common Rhino property)
activate (bool) – one go-no-go signal, or a list thereof

A (strings) – a list explaining the result(s)

bakeattributes bakeAttributes
GH 0.6.0012

GH 0.6.0018
GH 0.6.43
GH 0.8.2
GH 0.8.7
GH 0.8.52 w/ groups
obj (geom) – a list of objects to bake
name (string) – a list of names
layer (string) – Rhino layer name(s)
color (onColor) – screen+print color(s)
lineT (string) – the name of a linetype. Please only use with custom names.
pWidth (double) – printing thickness(es)
wires (int) – number(s) setting the quantity of wires, as in the property panel
material (int) – GH shader(s), containing a Rhino material
activate (bool) – one go-no-go signal, or a list thereof

A (strings) – a list explaining the result(s)

findIDfindRef findID
GH 0.6.0012
2009 06 19
x (geom) – a Rhino geometry

A (string) – The Rhino ID
A (MRhinoObjRef) – The Rhino Ref

Automatic Sections
GH 0.6.0012
GH 0.6.0043
2009 06 04
input (geom) – the objects to contour
axis (onLine) – a line identifying the origin and end of the sectioning axis
dist (double) – the interval between sections

geomOut (geom) – a list containing all geometries

meshOut (geom) – a list containing all geometries deriving from a mesh
brepOut (geom) – a list containing all geometries deriving from nurbs-types
pts (geom) – a list containing all geometries deriving from curves and lines

Continous redrawing
theEngine2theEngine1 theEngine

component for
GH 0.6.0012

Compatibility release for GH 0.6.0018 available, but users are encouraged to use the new timer within GH.
GH 0.6.0043
GH 0.8.0003 New

2009 06 06

isOn (bool) – one go-no-go signal
speed (int) – a period, expressed in milliseconds, that sets the refreshing rate
resetAt (int) – the last shown number in the series, which will be restarting at 0stopAt (int) – the last shown number in the series starting at 0
reset (object) – any object (or bool) passed here will make this component restart from 0

C (int) – the current count

bucketaddBufferaddBufferLtd Buckets

GH 0.6.0012
GH 0.6.0018
GH 0.6.0043
2009 06 10

x (list) – a list of points. For the bucket, it can be a list of anything.
reset (object) – any object here will make this an empty list

limit (OnInterval) – two numbers which set the max and min values for each internal point coordinate
recov (int: 0, 1 or 2) – a method to recover in case the internal value exceeds limits: wrap world (restart from other side of domain), limit (stop at the threshold, or restart from middle of the interval.

A (list) – the list in memory

renderanimation renderAnimation

GH 0.6.0012
GH 0.6.0018

GH 0.6.0043
GH 0.6.0059
GH 0.7.0055
GH 0.8.0002
GH 0.8.0004
GH 0.8.0013
GH 0.8.0065 updated by Jacek
200906 10

(four examples, see last one)

geometry (list) – a list of objects to be added to the scene before rendering
viewport (string) – the name of the viewport to use. If empty or non-existing, the active one will be used
filePath (string) – a name of an existing folder. If empty, the folder of the open document will be used. If document not saved, the current user’s document folder will be used

fileExt (string) – jpg, png, bmp, or another extension that the rendering engine supports
(shader) – a GH shader. If material has a name and name is already existing on the scene, then the material on the scene will simply be inherited. No need of double materials

current (int) – the sequential number of the frame
rectMem (bool, defaults false) – deletes redo+undo after each rendering
activate (bool, defaults false)

A (string) – a text, explaining the outcome

txtlines txtLines
GH 0.6.0012
GH 0.8.0061 New
face (string) – the name of the font
(bool, default false)
italics (bool, default false)
size (double, default 5.0)
content (string) – the text shown
pt (on3dPoint) – the point ancoring the text

A (OnLine list) – a list containing all curves

UdpReceiver updReceiver
GH 0.6.0019
Processing 1.0.5
+ UDP library

2009 08 31

port (integer) – a resonable port number

out (string list) – network echo
(UdpClient) – a .net framework udp client
A (bool) – message received
B (string) – message

62 Responses to “Grasshopper tools in C#”

  • Gabriel Says:

    Giulio Ciao!

    I need some help, however elementary, with your animation script. I have managed to get it running but I don’t quite get how it works, specifically the order of events. Once it’s gone through an animation it’s unclear how to reset and start over. I’ve tried “enable”-ing the timer and stopping and starting the timer (the check mark and the red circle-slash) but I still am not getting it. Is there an explanation somewhere?

  • Giulio Piacentino Says:

    Hi Gabriel,
    the script runs with these steps:
    – each object, including its materials and layers are added to the document if they are not already there
    – rendering is started. The script should wait now
    – all objects are deleted. Materials are not deleted, but naming of a specific material is unique, defined by its colors.
    Does this help?
    – Giulio

  • Fan Says:

    Alright, here we go again :D

    Dear Giulio,

    I have been trying to use your script for batch animation rendering. However, it seems like even if I assign multiple materials to separate lists of geometries, all end up rendered with the same material. Was your script written for single material rendering, or am I doing something wrong? I would really appreciate your help!

    Thank you so much


  • Giulio Piacentino Says:

    Dear Fan,
    I believe “the same material” comes from the different tree structures in the inputs. Please check that for each object there is a matching tree element of material. One rendering iteration is made by one list of objects and one list of materials. If the trees do not match, then the outputs wont either. Please feel free to open the component and check the logic. Thanks,
    – Giulio

  • giobuttu Says:

    I have been used your script for bakeAttributes
    and it is exactly what I was looking for. In addition I can also learn to programming with

    Grazie Mille


  • David Rohr Says:

    Hi Giulio,
    First of all, like everybody else I’d like to say great work coding and sharing: we need more of you guys!

    Secondly, I’ve tried to alter your animation code, aiming at getting vectorial pdf instead of bitmaps. So I directed myself to the end of the code where the rendering is happening (the one you reffer back to Mcneel’s website section on BatchRendering)

    Here is the section as you wrote it :

    app.RunScript(“_-Render”, 0);

    app.RunScript(“_-SaveRenderWindowAs \n\”” + savedLocation + “\”\n”, 0);

    app.RunScript(“_-CloseRenderWindow”, 0);

    Now to get my series of PDFs instead of bitmaps I thought I would just make it print through the PDF printer instead of render and just slap the savedlocation string at the end to get the same kind of serie.

    that’s the code modified:

    app.RunScript(“_-Print _go \n\”” + savedLocation + “\”\n”, 0);

    — MY PROBLEM : —
    My macro alone _-Print _go makes the dialogue box “Save PDF as” come out, but when I add your naming part, it doesn’t work.
    My explanation would be that yours work because the dialogue box opened by “_-SaveRenderWindowAs” is rhino generated whereas the one opened by “_-Print _go” is based on AdobePDF printer.

    Hope that it makes some kind of sense and hopefully on of you guys can help me out.


  • Giulio Piacentino Says:

    Hi David,
    sorry if it took some time to answer. I am still out of town. This question has to do with the way printing in Windows works (and AdobePDF works). Printing is not meant to save to a file, so -_Print does not accept parameters. Rhino 5 allows to use _-SaveAs as a file with Pdf extension (this results in an attempt to invoke the print call with special bindings).
    Hope this helps.

  • David Rohr Says:

    No worries,
    Thx for the tip, I’ll let you know if it worked

  • Danny Says:

    Thank you for these, great help!

  • Phillip Granke Says:

    Thank you for the invaluable tools here!
    I have been trying to get you bake attributes tool to export short material names as .3ds exports crop material names. Is there any chance you could add a feature where one could name the matierals list something more like bm1,bm2,bm3…?

  • Phillip Granke Says:

    Ok – its pretty easy to change the material name to the object name in your c++ but for people without coding experience .. it could be a useful to beable to name the materials.

  • Giulio Piacentino Says:

    The language is called C# (read C-sharp). You should be able to use a name in the “materials” definition. It should work by putting a panel with text instead of a Grasshopper material. The component should recognize this name and search it in the document.

Leave a Reply