|Grasshopper Wiki Pages|
|Robert McNeel & Associates|
Summary: Opensource Community page to help support instructors who are teaching the Grasshopper plug-in
The most up-to-date information is on the Grasshopper Group site. This page may give everyone a place to contribute and learn on teaching the Grasshopper.
This workshop will give students a functional understanding of Grasshopper, so that they can build on this understanding for more advanced projects of their own.
Document: Interface Explained.pdf
Definitions: Simple Math.ghx
The core of Grasshopper is the component. Detailed explanation of components.
Document: Objects Explained.pdf
Definition: Need to build up a definition that can be used to create these objects. Perhaps a circle based definition.
Parameters are a special type of component. Many times you might start with a definition. Parameters are singular entities that reference or contain data. In traditional programing they are most similar to declared variables. Typically parameters are your starting and controlling values in the definition. There are three types of parameters: Primitive, U\I, and Geometry.
Definition: Simple parameters - Build a definition with floats and integers. See the results. Start with the multi component. Set a float to each input. See the result. Change one of the inputs. See results. Then run one of the floats through a int param to round it off.
Definition: Simple parameters - Build a definition with points and circles see the results.
Definition: Simple parameters - Build a definition with points and circles. See the results. Start with the C,N,R circle component. Add a point param. set to C. Then set a Float param to R. See the result. Introduce that a param can handle multiple objects. Right-click on point. Then select multiple select. Pick multiple points. You should see many circles. If you want them to draw multiple Rhino points, then select them all with the Point param. You can now move the points around.
Definition: Simple parameters
These are for primary mathematical functions.
Definition: Simple Math
Definitions: Simple Math.ghx
Definitions: Simple Math.ghx
Definition: Create a cloud of points and a curve. Use and Expression to turn off points that are further from the curve than a specific value.
Definition: Change to include a point on the curve. Then using Boolean gates, set a points that are within the curve and the point.
Definition: Continuing with the Booleans definition above, sort the points based on their distance from an atractor point on the curve. You can use the Tag object to number the points to show their sort order. As an extension, you can draw a circle from the atractor point to the 6th sorted point.
Inside a Grasshopper workshop only the most basic of scripting concepts can be presented. A script component can be used to manupulate data in a way that existing components cannot. You can also create geometry with script components. Grasshopper can handle both C# and VB.NET coded components. It is important to note here that Grasshopper does not support RhinoScript directly. The VB.NET component is the best to use if you are coming from the RhinoScript language. There are quite a few differences between RhinoScript and VB.NET, so it will take time to make the transition. This course covers only VB.NET.
When you drag and drop a VB.NET component you get a base VB.NET code component. By default it has two inputs (x & y) and one output (A). It also has a message output (out) to see error messages.
To edit the component, just double-click on the component. You will get a basic code editor.
Each time a piece of data flows into an input, the script you type runs. In the most simple case a script can be used as a math function. This could also be done with a math function component, but it is used here as a simple example of scripting.
Sub RhinoScript(ByVal angle As Object)
' Set return value to the cosine of the input angle A = Cos(angle)
Here you can see that every time the slider is changed, the code runs in the VB.NET component. The last line of the code states A =. This is the place that the output value is assigned the A output on the component.
Also, there is a line the starts with a '. This make the line a comment. It is ignored by the code when it runs, but is used to comment the code to help us understand what is going on.
Perhaps the most important part of VB.NET programming is understanding variables and datatypes. Variables are containers of the information. The value of data in a variable can change within your code. It is through variables that you store, edit, and retrieve information. There are a few basics to understand about variables.
Variables are containers of information. And, like any real container, depending on what you intend to store in the container you may select from different containers sizes and styles. It is important to know the type of data you intend to contain in the variable. Each piece of data you intend to work with has a different size and therefore requires a different size container.
When you create a new Variable in VB.NET you must declare what type (size) the container needs to be in order to hold the information you have.
This line declares a simple Integer container with the name is i.
Dim i As Int32 * Reference Variable types String, Object. Dim name As String = "Arthur"
Dim name As Object = "Arthur"
Dim pt As New On3dPoint 'Initialized to (0,0,0) by the default constructor
Dim pt As New On3dPoint(1.0, 2.0, 3.0) 'User initialize point pt.x = 10 'Changing value of a member variable
Sub RhinoScript(ByVal point As ON3dPoint, ByVal dis As Object)
point.x = point.x + (2 * dis) point.y = point.y + (dis * cos(dis)) point.z = point.z
A = point
End Sub * Types * Multiple Outputs - Sometimes you want to output more than one variable each time the loop goes through. For instance if you have two input lists you would like to combine. In this example you have two lists of 5 items each. So you are going to go through your code 5 times. The problem is that you want to output one list with 10 items. So each time through the code, you will want to output two items. To do this you need to use a List object. Dim points As New List(Of On3dPoint)
To add a new member of a list use the .add method
Here is a full sample:
Sub RunScript(ByVal x As Object, ByVal y As Object) Dim Sorted As New List(Of Object) Sorted.Add(x) Sorted.Add(y) A = Sorted End Sub
Definition - opennurbs is the way we create and access geometry items in Rhino.NET. You can create points, lines, and many other geometry types.