Grasshopper

algorithmic modeling for Rhino

hi all,
ive been using grasshopper for about two years now and I'm getting to that point where I feel its time to jump into the world of scripting. I have read this part of the forum through and found many good resources for vb.net as well as others, also how to find the most current sdk amoung other things. I was wondering if anyone could give me some basic help on using GH for scripting however. I dont mean the scripting itself but for example using the vb button in GH for example assigning inputs and outputs. also where i can find a list of the commands that can be used, i know it has something to do with the sdk but its a little bit intimidating when you dont really know what youre looking for. I have some experience with vb and mayascript but not very much so i understand the basics of how these languages work but where I am having trouble is getting them into GH and getting a result out. 

Thank you!

Views: 320

Replies to This Discussion

Hi Nels,

the scripting component works in such a way as to try and synch the component layout with the RunScript() function. So the inputs in the VB/C# component become a bunch of function arguments for RunScript(). Let's say for example you want to create a DragonCurve fractal. This requires recursion so you cannot do it very well with Grasshopper nodes. A DragonCurve is defined by a base curve (non closed) and a number of recursion steps. The output is another curve.

So to set up this component you should rename the default inputs from "x" and "y" to "crv" and "depth" (for example) and also set the Type Hints to Polyline and Integer. A Type Hint can be set for each input parameter and it will convert the supplied data into the desired data type. This basically allows you to have a function that already uses Polylines and Integers so you won't have to try and cast the inputs to the required types yourself.

So once you've set this component up, you can double click it and the RunScript function should look like this:

Private Sub RunScript(ByVal crv As Polyline, ByVal depth As Integer, ByRef A As Object)

End Sub


Note that you cannot change this in the source code as it is auto-generated by the component. You can only change the contents of the function.

If you want to write additional functions or global variables or addition classes even, there's an extra bit of editable code below encased in "Custom Additional Code" tags.

I attached the DragonCurve script for your perusal.

--
David Rutten
david@mcneel.com
Seattle, WA
Attachments:
Thanks Dave! as usual very helpful and easy to understand. appreciate all you do to help all of us who dont quite get it yet to well... get it. keep up the good work!
I took about two years before I started writing scripts in Grasshopper, so I know where you're coming from. There's two learning curves that you need to push through before it starts to get really clear.

The first learning curve is just general programming concepts, like how loops, conditionals, and functions work, in whatever language your using, whether it is C# or VB.NET or anything else. You already have a head start on this from learning vb and mayascript. If you spend effort learning about how namespaces, classes, and inheritance work in your chosen language, then it will become way easier to learn someone's SDK. Otherwise you have to wait for the developers (like David and others) to write out tons of descriptions everywhere in their documentation, which usually takes a while if the SDK is still under development.

The second learning curve is the SDK itself. I learned after much confusion, that I should take the time to just look at the SDKs related to Rhino and read them. Look at the different classes that are used, and just browse through it a lot. You'll begin to see how the different namespaces are organized, and what they are for. Don't just wait until you need a command to look at the SDK, browse through it before you need it. Take one section and try to understand how it is organized, it'll save you a lot of time down the road. But if you want to feel comfortable writing code for a certain program, such as Grasshopper or Rhino, it pays to get an overall sense of how the SDK works before you start.

I hope this helps a bit.
yeah the SKD itself definitely has a learning curve. I was expecting more of an instruction manual or dictionary type thing when I opened it. not the case at all. thank you for your insight I think between your's and Dave's replies I should be able to get started any way. hello sleepless nights studying scripts!

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