 Howdy, guys. IndiePixel here. And in this video, I wanted to cover the basics of Python here inside of Houdini. All right, so just to accompany the Intro to Vex series on the IndiePixel YouTube channel, I wanted to make another series about Python because Python is very popular and is very powerful inside of Houdini. Much, much more powerful than I would say Vex because Vex basically operates solely on the geometry side of things where as Python, you could create whole pipelines with this. So let's start out by just learning the different places where we can actually put Python. So this kind of expects that you have a basic understanding of Houdini and Python in general. All right, so just to begin our level, we're going to walk through some of the better uses of Python inside of Houdini here. So let's go up to Windows and let's launch the Python shell. All right, so also take note that I am currently using Houdini 18. All right, so fresh and new. And you can see here that I've already gone ahead and created some code in here. All right, so what we can do with this is we can actually go and access this object level reference right here. So if we were to come in here and type something like obj equals who dot node and type in two quotation marks forward slash an obj. What that does is it gets us a reference to this obj object inside of Python. And with that we now have access to this space in here. Okay, cool. So with that, we can now then say obj dot create node. All right, and we want to pass in a geo node. All right, so we want to create a geo node and we want to give it a name of my geo so underscore geo. And look at that, we've actually created a geometry node. All right, so now let's go through and actually learn a little bit about all that code that we just wrote. So the who module is the kind of the root of all things Python inside of Houdini. All right, and you can go and find out more about the Houdini object model if we come over here and hit the little help button right here and wait for our help to load up. All right, we're going to scroll all the way down till we find the Python scripting option here. Awesome. So in here, we actually have tons of information about Python and how you start to write Python inside of Houdini here. And so the best place to start out is to go to this home introduction. All right, so the Houdini object model, this basically is the root of everything. So by accessing the who module, all right, so Python module, we have access to this who dot node. So if we come up here and we say who dot node and spell that correctly, there we go. There you go. All the way down to classes. So it's one of those kind of really root classes that takes care of all the different types of nodes here inside of Houdini. Awesome. So we come down here, you can see that we have information about all the methods or functions, I should say, that are available inside of the node class, which is inside of the who module. All right, so the who module and the node class. So what we're doing currently is we're going and looking for a node inside of the OBJ scene here. Okay, so if I come over here, and actually move this, make a little more room. So now what I can do is I can access this geometry node right here. All right, so we can say, let's actually hit up on the keyboard here, and let's actually store reference now. So I'm going to call this geo node is equal to the result of this OBJ dot create node. All right, so I'm going to hit enter again, and that creates another node right here. All right, very cool. So we can do since we now have a reference to that particular node, all right, because create node returns a node. And if we come over here and actually look for that. So we have the adding and removing. So we have this create node method here. All right, so it returns the who dot node. So with that information, we could say geo node dot create node. So remember now I have a reference to this my geo one right here. So you say, we're going to create a node inside of that. So I'm going to create a box inside of this guy. So I'm going to say box, and I'll give it a name of my box like so. All right, so if we jump inside of here, you can see now we have a my box node, and we have some geometry in here. All right, we can keep doing that for days. All right, so you can come over here. Let's say this time I want to create a sphere. All right, we'll call this my sphere like so. And there we go. We now have a sphere in our scene. Pretty cool stuff. All right, so that's pretty much the basics of just getting started with Python inside of Houdini. I should also note that you can actually go and load the Python shell from any of these panels over here. All right, so if you come over here, you can add a new tab. I usually add it down here. All right, so I'm going to go in here. And you can see now we have the Python shell. And the cool thing about this is I actually still have references to my variables or my objects that I created in that other Python shell. So I can say geonode.createNode like so. And you just make sure I spell the function correctly. And this time I am going to do a subnet. I'll call this my subnet. Like so. And look at that. So we saw references to our actual nodes that we got in this other Python shell. So you can work between those two. They're exactly the same. It's just this one's floating and this one's docked. All right, so with that, let's move on and talk about other places where we can go and put Python and how we can start to build up quite a nice set of foundational knowledge of how to use Python inside of Houdini. The next area that is of interest when you are starting to work with Python inside of Houdini is the session module. All right, so if we were to come up to Windows up here and we go to the Python source editor, what we can do is we can write to this who.session module. Now this who.session is basically a part of this particular hip file. All right, so it'll actually go. It's embedded into that hip file. All right, so which is why I should probably go and save this to my desktop. I'm just going to save it there for now. I'll just call this Python 01.hip. All right, so now this particular Python module is now embedded into my hip file. So what we could do is we can start to write some code that we can access from the shell. Okay, so let's say we want to kind of replicate what we're doing over here. All right, so maybe we'll take this a little bit farther. Let's get rid of all this stuff. So let's create a function. So we're going to say def. All right, for definition. And we're going to call this create some nodes like so. All right, there we go. So that's the start of our Python function right there. So what we need to do is get a reference to obj. All right, remember, that's this area right here. We want to get this object so we can add stuff to it. So I'm going to say obj as the variable name is equal to who dot node. And we're going to give it a node name that we want to look for. In this case, we want to look for obj. All right, so just like that, we now have a reference to our obj. And then I want to go and create a new geometry node so we can put stuff in there. All right, so we're going to say geo node for the variable name, because we're going to store this, we want to constantly have a reference to this particular node that we're creating. And we're going to say obj just like we did before dot create node. And we want to create a box node. And we want to call this my geo underscore geo. Now it's very important that you don't have spaces in this. If you do, then Houdini is going to throw an error for you, because it doesn't like having spaces in the node name labels always underscores. You'll notice that if you come in here and you create a geometry node, and you say my space box that automatically adds the underscore for you. All right, so just something to keep note. Also, if you ever want to find out the type of the node that you want to create, let's say for instance, I will go and create torus. All right, and we'll drop that down. You can always go and hit this little info button right here. And you'll notice that in these parentheses here, we have the torus type. All right, so that's what you would type into right here. That's that type of node. All right, so now we've got that all set up. All right, so let's actually see if this is working. Remember, this is our embedded module. We've created a function right here. So let's hit apply. We're going to not hit accept just yet. And now what I can do is I can come down to the Python show. And I can say who dot session. So we can come down here use their little IntelliSense. And we can say who dot session dot create some notes, notice how it's populated in that IntelliSense. So I'm going to hit enter. And you can see I get some errors over here. And that's because I created the wrong type of node. So you can see that at the very bottom of the error message, we get this invalid node type name. And that's because currently, I'm trying to add a node to OBJ. All right. And this is object level stuff. So we don't have a box node, we need to create a geo geo node or geometry node. There we go. Hit apply. And there we go. Let's test this out now. So we can just hit up on the keyboard to get to the last line. And enter and look at that. We just created a geo node. So let's delete that. All right, so now that we've got access to our geo node here, we can go and create our box node. So let's say box node is equal to geo node dot create node. So and let's add a box because now we're at the SOP level. So remember, we have different node types when we're at the OBJ level compared to when we're at the SOP level. All right. So now I have access to the box node type because I'm inside of a object level node. All right. So let's go and save my sphere. All right. Or I'm sorry, my box because what I was going to do next was create a sphere. So let's go and create a sphere node. Because what I want to do is I want to hook these two guys up together. So I'm going to wire them together and settle the display flags. So let's go and create node. And let's create a sphere type, which is another type of SOP node. All right. We'll call this my sphere. There we go. All right. So let's hit apply and come down to our Python shell over here and just hit up once so we get to the last function call. There we go. So now we have our my geo node. And look at that. We have a sphere and a box. And what I want to do now is I actually want to wire the sphere into the box. All right. So to do that, we're going to utilize the set input. So let's say set input. Let's look for that. So here we go who.node.set input. All right. So let's take a look at that guy. So all we need to do is give it an input index. All right. Thankfully, both these nodes just have a single index. So that'll be really easy. And then we have item to become input. So basically what we need to do is we need to tell the my box that we want the my sphere node to be the input. And then we need to set the output index from our sphere node. All right. So let's watch this in action. All right. So I'm going to say let's make another line here. We're going to say box node.set input. All right. And that works because remember, the box node is a node. So it's a who.node type. All right. And the node type is box. You can always go and actually print this out. So let's come down to the Python shell. I just want to make sure you guys understand this. So I can say who.node. And actually I need to store this as a reference. So let's get the box node. And let's say that it's equal to who.node. And we need to get a reference from obj down to my geo down to my box. And then what we can do with that is we can say print box node.type. And look at that. So it's a SOP node type. And for SOP box. So that's the type. And it's a SOP node. All right. So I just want to make sure you guys saw that. So now that we know that it's a SOP node type or of node type, all right, we can set its input. And I'm going to say we want to set the zero input. So the first input there. And I want to set the input object as the sphere node. And the output from the sphere node is going to be zero. There we go. So let's hit apply. Very cool. Let's jump open out and delete this guy. And then come to our Python shell and hit up twice there or three times to get back to our function call. All right. And there we go. So now I have my geo. And look at that. Our sphere is now hooked into our box. Awesome. So what if we wanted to actually set the display flag for this my sphere? That's pretty easy to do. All we need to do is come over into our Python source editor here. And we're going to say sphere node. All right. And we're going to say display or set display flag. So and we just need to set it to one for on. All right. So let's hit apply. And let's go and delete everything here. And let's hit up once and hit enter. And it looks like I missed an S. So let's set that guy. There we go. Hit apply. And hit up one more time. Let's make sure we clear out our OVJ scene there. There we go. So now inside of here, you can see that my sphere is now set with the display flag, but the box has the render flag set. So we just need to fix that. We just need to say sphere node dot set render flag to one. Like so. All right. Cool. So let's go and run that one more time. Delete these guys. Hit enter. And look at that. We've now dynamically set up a node structure. Obviously, it's not very fancy or anything like that. But that should give you a basic idea of how to start to work with nodes and how to create nodes and manipulate them, stuff like that. So I want to show one more thing. Now we've got this definition or this function up here all set up. We can actually create a shelf tool for this. All right. So let's go do that. I'm going to hit accept over here. All right. I'm going to minimize this here and get rid of this geo node. All right. And then let's open up the shelf area here. I usually keep it closed because I don't honestly use the shelf very much. I do everything down here and code stuff like that. But it's really useful. Sometimes you actually have a custom shelf if you're working on a particular project, you know, at work or something like that. So I'm going to come up here and go to shelves or actually new shelf over here. And that's going to pop open the new shelf wizard here that we have. And I'm going to give this the name of Indy shelf. And we'll say Indy dash pixel for the label. Hit apply and accept. All right. So inside of here, we can also write a little bit of Python inside of a tool. So let's go and right click on the shelf, say new tool. And I'm going to give this new tool a name of node creator, something like that. So we're going to call this make nodes. Good t-shirt actually. All right. And inside of the script editor over here or in that tab, you can write Python. In this case, because I've already typed in a bunch of Python into my source editor over here, I just want to have this particular tool called this particular function. All right. So all we need to do is access the who dot session. Look at that. Create some notes. All right, we're going to hit apply. And accept. And when I hit my tool, I get everything all set up for me. Pretty awesome. And that really is just scratching the surface when it comes to Houdini and Python. There's so much you can do to automate all this stuff. But you know, you got to start somewhere. And in my opinion, that's a really good place to start. Just understanding where to put Python inside of the different areas inside of Houdini. And also just how to work with the notes, some of the more basic functions and classes. All right. So those are kind of the bare bones things. One last thing I want to do is just edit this tool. So I'm going to right click on my tool, go to edit tool, and go back to the options and change the icon because that is just something fun to do. It's awesome to customize your own tools. Yeah. So let's go get a logo here. And I'm going to go and get one of the IndiePixel logos. And look at that. Pretty cool stuff. All right. So I'm going to leave you guys there in this video. I'm going to continue this whole series. And each week or every other week, make a new Python video. We'll start making some tools. And I'll show you guys some more tricks and stuff of how to automate like rendering or exporting. Lots of cool stuff you can do. All right. So thanks so much, guys. Really appreciate it. Talk to you soon.