Grasshopper C#

Hi guys,I’m studying C# to use Grasshopper C# compornent.

but there is few reference script, so It is hard to study.

How did you study C# ?

I’m just want to use grasshopper C# compornent, not visualStudio.

Let me know if there is a good idea.
Thank you.

https://developer.rhino3d.com/videos/

Is there no other?

I had an initial training, but this just gave me the minimum information.
The best and only true way to do it is learning the language. And once you know how to work with an extern library you can move to C# Grasshopper. You can do it the other way around, but this takes much more time. Learn at least about writing and calling classes. Unless you don’t know about them, calling them might be possible, but understanding will be hard.
And one aspect, which seems to be a general issue. Coding is simple to start with, but very hard to master. You need time and as such don’t expect to learn anything from video tutorials only. Buy a book, better find a local mentor and practise a lot.

1 Like

In addition:

In Grasshopper C# you usually do these things quite often

declaring and initialising geometrical objects and numeric variables (data types -> Classes, Struct etc.)
doing simple math
calling prewritten methods/functions (Rhinocommon.dll -> description is Rhinocommon SDK)
doing this iterative (in a loop) or recursive
adding the result to or getting items from a collection (list,arrays, trees).

I started with BASIC, then had about a 10 year period of no programming, picked up RhinoScript again at university, then moved to VB6, VB.NET and eventually C#. I came into C# already knowing how .NET worked so I only had to learn the syntax.

C# in Grasshopper is not special in any way, any online tutorial will basically work. If you’re entirely new to this there are about four things you will need to learn:

  1. C# syntax: loads of great books and webpages, and of course StackOverflow has pretty much all the answers to specific questions already.
  2. .NET Framework: The framework provides the standard types you’ll be dealing with. Text, numbers, collections, mathematical operations. MSDN lists all the types and methods that come courtesy of Microsoft.
  3. RhinoCommon: this is the SDK that comes with Rhino. It provides the types and methods that are Rhino specific, such as geometry (points, vectors, planes, curves, meshes, transformations, intersections, etc.) and document management (layer and user data access, file writing, undo/redo steps, etc.) and various interface related stuff. The types and methods are online, sometimes even with explanatory comments.
  4. Grasshopper: you may not need much of this if you’re just doing regular calculations in C# components, but you’re running inside GH so sometimes it’s unavoidable. The GH documentation is also online, and can be downloaded via the GH help menu.
6 Likes

Hi,

on this page http://petrasvestartas.com/C-for-Grasshopper you can download example gh files, they helped me out several times. Also the pdf explains well the baiscs. A few days ago I stumpled over this one which also is very nice and compact:https://issuu.com/knazar/docs/csharpforgh_reference_1sted

What I did at the beginning(I am still a beginner) was recreating simple gh scripts, like connecting 2 lists of points with lines etc. People here helped everytime I got stucked, the thing is to start and gain expierence.

Also read the Grasshopper Developer section on this Forum and download other peoples scripts and try to understand.

4 Likes

Hi,Tom

Thank you for the advice.
I will buy a book and learn C# in the first.

Thanks to you , It looks like I will be able to improve.

Hi,David

Thank you for your kinf of instruction.
I will work hard to learn this four things.

Hi,Baris

These two Documents are very Useful.
I would like to use these documents as a reference.

Thank you very much.

Not sure if you got me right, I was talking about the definitions you can download there.
This ones:

There is not much more to it than in those videos, besides knowing C# itself in which case better to go through some general C# tutorials like the ones on Microsoft’s website.

3 Likes

yes , I got this . so It is very functional.
Tnaks you !

Hi,Michael

Thnak you for the advice.
It seems that I have to learn C# in the first.

Hi there, this is a set of tutorials that help me a lot with C#, but certainly from 0 to C# or VB is a very far jump, so personally I learn C# by translating scripts that I find in this forum to Python, In this way I could understand how Types in C# works and why it appears to be a very redundant language.

2 Likes

Hi, Antonio
Thanky you for advice!
I will try my best from a easy scripts.:thinking:

I’ve been after something like this. Is there a more complete version of this diagram somewhere ? It just needs to be for rhinocommon.geometry.

David, I’m really struggling with the Rhinocommon side of things. Everything else is fine - I’m a software developer - but I need practice doing geometric coding and also if there was some sort of rough guide to using rhinocommon like one would use rhinopythonsyntax / rhinoscript it would help.

If you can’t find any answers here or by searching this forum, I guess you’ll just have to ask any specific questions.

RhinoCommon adheres reasonably to the .NET standard guidelines, but it has some idiosyncracies that are carried over from the C++ part of Rhino. And we arguably also made some bad decisions early on that cannot now easily be fixed, such as mutable structs.

The aspect that most confuses people in my experience is how the various geometry types relate to each other.

For example there is a Rhino.Geometry.Curve type which serves as the base for all the curves that you can find inside a Rhino document. However you’ll never (or rarely) get an instance of this particular type, as there are a set of more derived classes which handle the specific types of curve that Rhino understands. For example LineCurve, ArcCurve, PolylineCurve, NurbsCurve and PolyCurve.

However these derived types all carry a lot of baggage around with them due to the demands made by the Curve base class. If you’re writing an algorithm which only deals with pure lines and circles, you’re usually better off using the separately implemented Line, Circle and Arc structs.

Ok, so speaking of how the geometry types relate to each other, is there some sort of class hierarchy diagram showing the full set of rhinocommon types I need to concentrate on? you see then I’ll just have a finite list of things to search on how to use on the forum/internet and I’ll also see how they relate to each other.