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 behaviours.

This list of C# scripts is a work in progress and is open for requests. Supporting  v. 0.6.0043.

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.0043
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
findRef
GH 0.6.0012
2009 06 19
x (geom) – a Rhino geometry

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

Automatic Sections
contours
contours
contours
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

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
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
material
(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

fonts
txtlines txtLines
GH 0.6.0012
2009 06 04
face (string) – the name of the font
bold
(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

Networking
UdpReceiver updReceiver
udpSender
GH 0.6.0019
Processing 1.0.5
+ UDP library

2009 08 31

port (integer) – a resonable port number

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


23 Responses to “Grasshopper tools in C#”

  • AP Says:

    Great definition. I had a question about the Color attribute. I had wanted to turn on that attribute for the autobake toggle… but how is the color syntax formatted? Is it something like this?
    att.m_color = new OnColor(255,255,255)
    where the three numbers are RGB values? Or would you include a hexidecimal value? Or is there I’m completely missing. Other than that, this definition works great. Congratulations.

  • Giulio Says:

    Hey Andy, glad you like it. The new “advanced” definition should now do what you asked for.

  • AP Says:

    Amazing job! These are some great tools. Thanks for all of the hard work.

  • Thomas Wingate Says:

    Giulio,
    Great stuff. We had Andy over here at the lab in the weekend and he pointed us in your direction. Your code blocks will be excellent starting points for the research on multi disciplinary optimization and topology we are doing.
    Thanks & I’ll be sure to keep you up to date with feedback.

  • didi Says:

    Great work on theEngine components, love ‘em!
    take care,
    d.

  • Peter Varo Says:

    Nice work, they are very useful! Thank you very much!
    P

  • Gabe Says:

    hey G

    these are great. to get a still instead of an animation would that be easy to get using your animation component?

    regards

  • LaN / Live Architecture Network » Archive » Grasshopper Processing v2 Says:

    [...] component to continuously refresh the GH canvas. You can find that component at his site:http://www.giuliopiacentino.com/grasshopper-tools/. The processing sketch was hacked together from a simple processing animation found at [...]

  • LaN / Live Architecture Network » Archive » Maya Fluid to Grasshopper via UDP Says:

    [...] the fluid as a Surface.  As with the rest of the UDP experiments, Giulio Piacentino’s “The Engine” component made the refreshing of the Grasshopper canvas [...]

  • Alessio Says:

    Hey Giulio, great job!

    Greetings from Bologna!

    Best,

    Alessio

  • WANSOO Says:

    Hi,
    I am really interested with your script and trying to utilize it.
    But I am having a problem with inputing your script to my C# tool.
    What I am doing is just copy & paste your script into the portion named “your code”.
    Could you let me know what’s wrong with it?

  • admin Says:

    There is no need to copy-and-paste, all you need to do is download the .ghx file (in some older browsers right-click the component and select “Save target as…”) and open it in Grasshopper. Should work with GH 0.6.12

  • Andrew Says:

    Hi Giulio,

    similar basic question as Wansoo’s. I’ve tried opening or merging bakeAttributes. But an IO always pops up with 46 messages, mainly components failed to deserialize. Any hints on using this C# component will be helpful. Ta.

  • admin Says:

    Hi Andrew, there will be soon an update with hotfixes for GH 0.6.0018. That release changed some inner workings in GH, so files are now not 100% compatible with version 0.6.0012. There’s nothing to worry about, everything on this page will be compatible, or with two releases. I’m glad if anybody can help in this task.

  • duduche Says:

    Hello !

    Great job indeed ! Trying to use theEngine but I’m having the following error :
    The type or namespace name ‘EH_SolutionCause’ does not exist in the namespace ‘Grasshopper.Kernel’ (are you missing an assembly reference?)

    Even if I do not have an error with the theEngine using stopAt, nothing happens.
    GH version 0.6.0018 – Rhino 4SR5 (do I need 4SR6?)

    thanks !!!

  • admin Says:

    The latest compatibility release should now work!

  • oladayo Says:

    great job guilio, unfortunately i have only used the contour command… will be able to explore others in the next few weeks….

  • mei Says:

    thanks for the C scripts, they are very very helpful …. i am using the bake attributes script, using version 06.0012
    i don’t understand how the delete materials boolean works … do i need to make clusters of my objects first before baking? where does this component connect to?
    many thanks

  • Giulio Piacentino Says:

    Hi Mei, glad to help. The “delete materials” is only intended for advanced use (if you are using really many materials). Unselect all objects in Rhino, then use the boolean command once. Save your 3dm model, close it and reopen it in Rhino. You document should not contain any material now!

  • rex Says:

    HI Giulio,

    Your site is great, thanks for all the sharing. I have been trying to add the “renderAnimation” component into my grasshopper definition, but did not manage to render the animation. Basically, I want animate two walls where the sun would move over the course of a day. The hours are controlled by a slider. My question is how do I tell Rhino to render, is there a switch created by the component?
    Thanks

  • mei Says:

    many thanks giulio, will try it out …

  • Dan Cimino Says:

    great post – helpful for my grasshopper

Leave a Reply