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
GH 0.9+ 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
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
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
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
GH 0.8.0061 New
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


62 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

  • 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

  • Brian Says:

    Hey Giulio

    Amazing set of tools, I have successfully implemented your RenderAnimation tool into my GH file, but am wondering if there is any way to assign a material to a specific geometry through the tool. I understand that it assigns an equivalent amount of materials to the amount of geometry that is inputted. Simply put, i wiould like to have half the geometry one colour, and the other have another? Can I be helped?!?!?!

    thanks

  • Giulio Piacentino Says:

    Hi Brian, without knowing more of your definition, it’s difficult to tell which one would be the easiest method. One that comes in my mind is to use the “duplicate data” component in Grasshopper, to obtain the right amount of materials. Also, you could make a series of indexes and take the right shader from a list of two. Please let me know if I can help you further with this. -Giulio

  • Stan Carroll Says:

    Giulio,

    I am currently taking my first C# programming class to learn to write Grasshopper components. Ultimately I need to take what I learn from the class and implement it into GH. I am contacting you to see if you would be willing to share a C# code file with me so I might start to use it as a template to write my own C#/Grasshopper components. The best file for me to review would be any simple file to give me a sense of how it might come together. Any leads to any other resources regarding same would also be very helpful.

    Thanks for considering

    Sincerely,

    Stan Carroll
    beyondmetal.com

  • Giulio Piacentino Says:

    Hi Stan, I’m contacting you by mail.
    – Giulio

  • hana Says:

    hi Giulio, i just discovered your render animation component and opened it in Gh. how do i activate it? thanks

    hana

  • Dan Says:

    Hi Giulio, I just started playing with your txtLines tool. Very Helpful definition. Is there a way to add toggles for ‘curves/face/solids’ + ‘allow single stroke fonts’ that are part of the textobject rhino method? (http://rhinotoday.com/2009/07/single-line-fonts-in-rhino/). Thanks for taking a look.
    -Dan

  • Giulio Piacentino Says:

    Hi Dan,

    as Luis was pointing out here, the only possibility that is available at the moment is to script the command. Possibly RhinoCommon will soon overcome the current limitation, but for now, scripting the command (or doing the operation manually altogether) are the only possibilities I know of. I haven’t tried Benjamin’s definition in this discussion yet, but looks promising.

    – Giulio

  • Marc Says:

    Giulio… any plans to update these tools for use with GH 0.7? Thanks.

    Marc

  • Giulio Piacentino Says:

    Hi Marc,

    in theory, Gh 0.7 should support all these scripts in the legacy component.
    But if there are any problems please let me know!
    Thanks,

    – Giulio

  • christoph Says:

    hi giulio ,

    recently switched to GH7 and tried to use component in the bakeMostAttributes-43.ghx
    unfortunatly the legacy component doesn´t seem
    to work. is there any way to bake colour and material in the current grasshopper 7

    thx
    chris

  • Giulio Piacentino Says:

    Hi Christoph,

    which attributes are you interested in baking?
    Material is difficult in the current state of RhinoCommon, but should soon be possible again, other are already possible.

    – Giulio

  • christoph Says:

    thx for your fast reply
    was wondering if i could render the colour output of for instance the surface curvature evaluation because i am trying create formdepend shaders.

  • Giulio Piacentino Says:

    The easiest way to have some procedural colors/materials on a surface is apply colors to a corresponding Mesh.
    “C” input in the Mesh component are vertex colors – just set it, then the mesh can be baked even with the normal Grasshopper button.
    I hope it helps,

    – Giulio

  • Elan Says:

    Hi Giulio,

    Im an architecture student at Mcgill university. I’ve just gotten started with grasshopper a few weeks ago and I’m currently having problems trying to contour a surface.

    I have a surface in Rhino, I need contour lines for this surface as if it were a topographical map. Is there any way to do this on Grasshopper?

    Thanks,
    Elan

  • Giulio Piacentino Says:

    Hi Elan,

    I do not have tutorials for this, but intersecting a series of planes with either a mesh or a polysurface should give the result you seek.
    I remember this nice example: http://www.grasshopper3d.com/photo/contourlayout-1?context=latest

    – Giulio

  • Daniel Davis Says:

    Hi Giulio,

    I modified your script to work with Grasshopper 0.7. You can find it here: http://parametricmodel.com/detail.php?item=10

    Daniel

  • Igo Says:

    Hi Giulio. Great Components I have to say. Thank you for sharing.
    I would like to ask you something because I’m having problems with renderAnimation component in GH 0.8. Do you if I you will upgrade soon to use with 0.8 version? Thank you.
    Igo

  • Giulio Piacentino Says:

    Done, thanks for reminding me.
    – Giulio

  • mairen Says:

    Hi Guilio, amazing stuff, but do you know how to make the renderAnimation component work with GH 8.0?

  • Giulio Piacentino Says:

    It is, isn’t it working?
    – Giulio

  • Nick Says:

    Does the renderanimation work in rhino on its own, or does it need to be rendered using sometihng like vray? i cant find the batch render option in rhino…

  • Giulio Piacentino Says:

    Hi Nick,
    it should work for any renderer for which the _Render command works. Yes, the Batch render option is there in VRay.
    – Giulio

  • Nick Says:

    Thanks for the speedy reply Guilo, unfortunatley i am a very confused. i think it may be that my university has grasshopper 6.0001, and you used 6.0002. its having a problem with timer failing to ‘deserialize’.

    I will give it another go on my home computer which is uptodate.

  • Victor Leung Says:

    Hi Giulio

    I’m thinking of a bake update tool.
    That is similar to the Bake Attribute tool, but that it could overwrite geometries in Rhino with new ones, identified by their names.

  • Giulio Piacentino Says:

    Hi Victor, please go ahead!
    You can find working code for that in the RenderAnimation script. It does not keep track of names, but rather by ID (Guid) or reference. You will need to come up with a way to store the “these are baked” state in the component, though.
    – Giulio

  • scott crawford Says:

    Hi Giulio,

    I’ve been using your renderAnimation script for awhile and love it, but today I ran into a problem. The component says that all of the geometry has been added but then I get an error that there is “Nothing to render”. It seems to be file specific because if I open a new file I have no trouble. Any clues as to what might be wrong with my reject file?

  • Ben Anderson Says:

    Hi Giulio-amazing work here…I’m trying to make your render animation script work, and running into issues with reflectance-is this an inherent limitation of the GH material component? I can edit it’s ‘shinyness’ value, but that doesn’t seem to allow me to vary for materials with high specular values (glass) to something slightly more matte (plastic). Any thoughts? Is there a workaround within your script? I know very little about coding / scripting in VB. Thanks!

  • Giulio Piacentino Says:

    Hi Benjamin,
    thank you. I’ve answered on the Grasshopper forum and also added the definition here. Have a nice Sunday,
    – Giulio

  • Giulio Piacentino Says:

    Hi Scott,
    I’ve sent you an email. I’ll need a little more details, but maybe is it possible that a material already exists in the document?
    Or maybe could it be that there are too many materials?
    – Giulio

  • WF Says:

    Hello Giulio:
    I’ve posted your site onto our website, and got your link through a mutual friend Judith Mussel. It is a pleasure to see what one can do and push the limits of Rhino and GH. I’ve been a long time user of Rhino, used Alias in the past and also Max user, along with other rendering engines, but really like what you’ve done with WeaverBird.

    Hope to be in touch.
    Kindly,
    _WF

Leave a Reply