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 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 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) |
|
findID findRef GH 0.6.0012 2009 06 19 |
x (geom) – a Rhino geometry
A (string) – The Rhino ID |
|
Automatic Sections | ||
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 |
|
Continous redrawing | ||
theEngine
component for 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 |
|
Buckets
GH 0.6.0012 |
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 A (list) – the list in memory |
|
renderAnimation
GH 0.6.0012 (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 current (int) – the sequential number of the frame A (string) – a text, explaining the outcome |
|
fonts | ||
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 | ||
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 |
April 7th, 2011 at 8:52 pm
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?
April 9th, 2011 at 5:57 pm
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
April 9th, 2011 at 6:07 pm
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
Fan
April 9th, 2011 at 8:01 pm
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
May 17th, 2011 at 5:16 pm
Giulio,
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 VB.net
Grazie Mille
GB
August 4th, 2011 at 2:11 pm
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.
David
August 15th, 2011 at 6:01 pm
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.
August 15th, 2011 at 9:17 pm
No worries,
Thx for the tip, I’ll let you know if it worked
November 3rd, 2011 at 1:37 pm
Thank you for these, great help!
December 15th, 2011 at 3:19 pm
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…?
December 15th, 2011 at 3:25 pm
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.
December 16th, 2011 at 6:21 pm
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.