Updated
1/7/2021Released
5/30/2019Note: Because this is an ongoing series, viewers will not receive a certificate of completion.
Skill Level Intermediate
Duration
Views
- [Instructor] Hello and welcome. This is the first in a series of videos focused on coding custom components in Grasshopper. Intended for people who are novice to coding, who are coming at this without any prior computer science experience. So you've probably seen the custom components in the Grasshopper interface, the C sharp component the Python component, the VB component. If I grab the C-sharp component, I open it up. It just creates a little space for me to write in some custom code and build my own functionality into a custom component. But this can seem inaccessible to people that are new to programming, little harder to work with. And the question is why would you dip your toe in? So I want to talk about a really simple basic use case where someone who is completely new to coding might take the time to build a really simple custom component. So imagine you are working with surfaces. There's lots of tools that have been built up over time within Rhino that haven't been implemented fully in Grasshopper either because they haven't been implemented yet or they don't lend themselves easily to the interface paradigms within Grasshopper. So I have a surface here. Imagine I want to extend this surface. I type in extend and I can extend the edges of the surface, pick any of the edges, really useful command if you're working with surfaces if you're trying to connect things together. If I go to do the same thing within Grasshopper, double click and I start typing extend, I see extend curve but I don't see that same functionality extend surface. So the reflex solution to this for most Grasshopper users is to hop on to Food4Rhino and find a plugin that has that functionality added in. And I'm sure there is one, I don't know off the top of my head which plugin has extend surface implemented but it is a command in Rhino. And if it's a command in Rhino, it's something that can be added to Grasshopper relatively easily. The problem is as you start adding more and more plugins you create all of these dependencies. So if someone wants to use a script that you've made, they have to also install the same plugins and it can actually make the interface harder to work with because there's so many components available. So I want to show you an alternative to that. It's actually really easy. So if I go to the Rhino API, this is the documentation that describes how all the underlying code is running within Rhino. So if you want to access it as a plugin developer or just, you know, writing little scripts, this is the documentation that tells you how to do it. And it's really well done for Rhino. It's one of the most powerful features of Rhino because it makes it so easy for people to build extensions. So the Rhino Common API is the documentation for sort of the central core functionality that's accessible using C-sharp or VB, they're kind of the same thing. So I'm going to the Rhino Common API, I'm going to type in extend. And I find that same command, surface extend, right? This is the command that's running in Rhino. And if I click on it, it explains exactly how this works within Rhino and how it could work if I add it to Grasshopper. So it tells me, okay, take a surface. The surface has a method that you add to it called extend. You need to tell it what edge, how far, whether it is smooth and what you get back is a surface. So right here, return value surface. So let's try adding that in our script. So here's my C-sharp component. The first thing I'm going to do is I'm going to set up the input. So I'm going to select this. I'm going to change the name to surf, and I'm going to go down to type hint, and I'm going to change this to surface and I'm going to get rid of the Y and I'm going to get rid of the out. The out is it allows you to print stuff. So we're not going to do anything. We're going to keep this very simple for this example. And I'm going to go to params, I'm going to grab a surface. I'm going to set that surface to the surface in my model and plug it in. And I'm going to open up my component. And because I declare that input, I said its type as a surface, when I start typing, I'm going to say a, which is the output, equals srf dot and then it will start autocompleting to help me figure out what it is I'm trying to do. So it's going to tell me all the things that that surface can do. All its methods, all its functionality that's built in in that Rhino Common API. So I'm going to start typing extend and there's the function that I'm looking for. And then I'm going to put in the parentheses, and what's nice is if I type this, right, you can see it's starting to autocomplete, it's hiding quickly. But the first thing I want to do is do Rhino geometry. ISO status dot north. And this is just called an enumerated value. It's a bunch of ISO status options. So I want to just pick one, I'm picking North. It could be South or East. Those are the different sides of the surface. And the next thing I want to do is the extension length which is a double, which is basically just a number. So we'll do, just to make sure we can see that it's working we'll do something big, like 15 and then Boolean smooth. I'm going to set that to true. That's a Boolean value, close out my parentheses. And I put the semi-colon at the end to tell it that's the end of the line. And I'll say okay. And now let's connect the surface component at the end and make sure that this is working. So there you see the surface extension. So this is just a single line of code, right? This is really pretty accessible to most people regardless of how much experience you have writing code but it allows you to take functionality that's in Rhino and put it in Grasshopper where it didn't exist before.
Share this video
Embed this video
Video: Why coding: C#