Grasshopper

algorithmic modeling for Rhino

Hi all. First post, happy to be here.

A quick introduciton. I am a Norwegian architecture student who just started on my Master education in Germany after 2 years of working experience in an architecture office. Before I took my bachelor of architecture I had a uni degree in informatics and worked 5 years as a Java programmer.

I was just introduced to Rhino and Grasshopper last week in a uni course, and all of a sudden it seems as though my two carreers have found a tangent point.

I am very excited about the outlook of using my programming skills in my architecture. I am still not quite sure where C++, C#, VB.net and Rhinoscript fits in the scheme of things? I just read through a Rhinoscript primer, and though the syntax and programming is no problem, I am left with the question of whether I should write code in Rhinoscript or with Grasshopper in combination with VB or as C# standalone code? I have found lots of documentation, but most of it is geared towards helping users with no programming experience getting started; for them the recommendation is rhinoscript?

But if the programming is not the problem, what is the best practices/most common use of these tools? Grasshopper with C# (or even J#?)?

I would greatly appreciate if you could give me a recommendation on what where to start; with what tools and programming languages.

Cheers,
Eirik

Views: 592

Replies to This Discussion

Hi Eirik,

welcome to this forum!

RhinoScript, in its general meaning, is the scripting infrastructure built upon the VBScript language for automating Rhino as a modeler. You can type the _EditScript command in Rhino 4 to have the default editor (and F1 in there to open the help). It is setup as a large number of functions, all available in the form of Rhino.DoSomething(). Mostly, DoSomething is either Add or Delete an entity from the current document.

Grasshopper is a plug-in for Rhino developed and distributed for free by McNeel. It is based on RhinoCommon, which is the new .Net SDK - which is being written for the upcoming Rhino 5. Grasshopper provides all Rhino users with a powerful yet understandable interface for automating their tasks and exploring geometry though a visual interface. This might be called the Grasshopper visual programming language. The first step to learn Gh would be getting acquainted to this model. None of the Grasshopper components modifies the current document, only the Bake button does so. This and another reason mean that RhinoScript cannot be directly used inside Grasshopper.

RhinoCommon as a library is written in C# and Grasshopper itself is written in Vb.Net and C#.

Grasshopper offers scripting components that are compiled in debug mode, on the fly, just when you click "Ok", for both C# and Vb. Also, at McNeel we are testing ways to provide a Python interpreter via IronPython to Grasshopper. A nice advantage would be that variable input would also be acceptable in this model. Rhino 5 already has a Python interpreter for automating Rhino.

Finally, Grasshopper has a public yet (warning here) quite rapidly changing SDK. You can download it via the _GrasshopperGetSDKDocumentation command (comment: you need to load Grasshopper in order to see this Rhino command). The help file also explains how to setup your own components and make Grasshopper load them. This is useful for fairly non-conventional usages.

I hope this intro is helpful.

- Giulio
_____________________
giulio@mcneel.com
McNeel Europe, Barcelona
Ah, about the topic (Vb.Net or C#) - it is completely up to you and your preferences. Certainly, C# looks very similar to Java, yet has some differences - the biggest one you will encounter in RhinoCommon being ValueTypes (which behave like int in Java - so, for example, assignment means copy).
Examples of ValueTypes are Vector3d and Line.

- Giulio
_____________________
giulio@mcneel.com
McNeel Europe, Barcelona
Hi Giulio, and thanks for your quick and informative response.

I guess my question about C# and VB was a bit preliminary.. I first need to understand the usage of GH and when to script and program first. Your introduction was very helpful. Do I have the correct picture (albeit simplified) when I say that GH is a visual tool for modifying a model parametrically, and that code can be written and compiled into it for usage out of the normal, but that a lot can be achieved without programming?
And another alternative is to script the same behaviour in Rhinoscript?

Are there specific things that are achieved only through scripting/programming?

I will continue with some rhinoscript and grasshopper tutorials and hopefully get into this exciting world of algorithms and architecture.

Cheers,
Eirik
> Do I have the correct picture (albeit simplified) when I say that GH is a visual tool for modifying a model parametrically
Partially yes, in the sense that Gh can be used also and even more probably to create a model parametrically or algorithmically.

> code can be written and compiled into it for usage out of the normal, but that a lot can be achieved without programming?
This is one of the intentions.

> Are there specific things that are achieved only through scripting/programming?
Yes, looping and recursion are not visually expressible in Grasshopper. You can use Galapagos to obtain something like a large, unconventional loop, but you cannot at the moment extract partial results (geometry) from it.

Good continuation,

- Giulio
_______________
giulio@mcneel.com
McNeel Europe, Barcelona
Thanks Giulio.

I am trying to learn rhinoscript and grasshopper and the integration of c# simultaneously... I thought if I try the rhinoscript part first and then rewrite it to c# I can get somewhere.

Just a quick question on how to get the c# code to work.
I have added a c# component in GH, written a short code that creates two points from input sliders and then creates a line from them. Although the c#-component doesn't show any errors, nothing appears in rhino? How do I get it to create a model in rhino?

For clarification purposes. I have rhino 4, and the 0.8 version of Grasshopper. As far as I understand the c# uses the RhinoCommon SDK. So I created points from Point3d and line from Line in the Rhino.Geometry namespace. Or is this just working with Rhino 5?

thanks,
Eirik
Attachments:
You need
//assigns to the output parameter
A = l;

in the end of the script, so that Grasshopper knows which geometry you are passing to the outputs of the script. (A is null by default.)
Grasshopper has a special work-in-progress version of RhinoCommon that it can load to communicate with Rhino 4 for the time being. In Rhino 5 and in the future, it will use the version that ships with Rhino.

Thanks,

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

PS: Please, in the future and if you have longer definitions, attach the .ghx so that one can test the script without writing everything from scratch.
Fantastic!

Yes, it works : )

And if I want to create more geometry within the script, say points along a spiral, since A is a reference var I can't assign each point to A, it will only draw the last? How do I create multiple instances within one script component?

Without success I tried this code:
Point3d a;
Point3d b;
object[] geometry = new object[3];

for (int i = 0; i <= 2; i++)
{
a = new Point3d(x, y, z);
b = new Point3d(x + i, y + i, z + i);
Line l = new Line(a, b);
//assigns to the output parameter
geometry[i] = new object();
geometry[i] = l;
}

Cheers,
Eirik
Thank you for asking these questions. Some of these have already been answered a couple of times on the Vb.Net and C# corner.
However, I know that finding them is difficult!

Grasshopper dynamically checks the type of the returned object and will behave accordingly. If you pass an IEnumerable, (like List<SomeThing>), it will read it as a list. If you pass a DataTree<SomeThing>, it will read it as a tree.

Note that Grasshopper will automatically iterate your component RunScript method as necessary to give the type access you need (for example Point3d, List<Point3d>, or DataTree<Point3d>).

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

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