 Howdy, guys. All right, so in this video, what I wanted to do was walk through the process of exporting our parameters to JSON file. So in the last part, we went through how to write to a text file with Python. In this video, we are going to talk about JSON. So let's go and create a geometry node here in our network view here. And again, I'm just going to make a really simple box maker HDA. I'm just going to put a box inside and then jump up and out and let's go and make a digital asset out of this. All right, so I am going to do IP to colons for the namespace and then 1.0 for the version number and I'll get rid of these colons here for the name. No reason to have those in the actual label itself, and I'm just going to save this to the desktop. Just for now hit accept and we'll destroy all of our spare parameters. Very cool. All right, so then what we want to do is we want to go and hide all of our default UI. So we can add our own custom stuff in there, just like usual. And I'm going to go and I'm going to create a couple floats in here to test with and maybe a string parameter. How about that? So let's drag a string parameter in there and let's go and name these guys appropriately. So I'm just going to call this float a and then give float a for the label and we'll do float b for the internal name and then float b for the label and then for the string. Let's call this my string like so, my string. Very cool. Hit apply. That way we get our parameters, our own custom parameters in there. Okay. Very cool. What we want to do is we want to then come into the scripts tab over here and get a couple of functions set up. So the first thing we need to do in order to write Python for our HDAs is we need to go down to this event handler in our type properties window and we want to go and select the Python module. That gives us a Python module to work with so we can start typing Python code. All right. So first one we're going to do is we're going to write our parameter. So we'll say write prams for the name of the function and I'm going to pass in the quarks dictionary that is provided to us by Houdini. That includes a bunch of information about this particular node. So the HDA node itself. All right. So just to make sure that this working I usually like to put in a print statement and we'll just say this is working. All right. I'm going to hit apply and then over in our parameters, let's add a new button. So I'm going to drag and drop a button and I'm going to call this export prams and we'll say export prams for the label. There we go. Okay. So now we have a button in place that we can use to click and actually fire off our code. Now we need to hook up that button click event to our function over here. Okay. So let's do this. We're going to do who.pwd refers to this node. All right. So this holds all that information about that node. Now we're going to type hm for Houdini module or HDA module, I should say sorry. And then we need to go and put a dot and we need to put in the name of the function that we want to call from this button click. All right. So I'm just going to do that and we're going to pass in our quarks. All right. That's a dictionary holds a bunch of information about this particular node. So with that all done, all right, let's make a little bit more space so you guys can see it all. There we go. With that done, we should down here in the Python shell, see this is working when I click this button and look at that. That does in fact work. So if you don't have your Python shell open, just hit this plus button right here and go to your Python shell. There you go. There we go. All right. So now that we've got that working, it's pretty easy to start to write out our parameters with JSON. So let's get rid of this print statement. And the first thing that we're going to need to do is we need to import, we get rid of that there, we need to import JSON. So the JSON module. All right. This comes with Python and it allows us to read and write JSON files. Okay. So that's very important in this step. So the next thing that we want to do is we want to get the parent node. All right. And parent node refers to this node, all right, this geometry node, this HDA. And the reason why I need to do that because I need to read all the parameters that we just created. All right. So I need to read all that particular data. So we need the node itself. So I'm going to say parent as a variable name. And so parent is going to be equal to quarks to square brackets, because we want to access one of the elements in the dictionary. And that element is the node. All right. And that will refer to this particular object right here. Cool. So now with that, what we can do is we can get all of the parameters. Okay. So let's take a look at this. What I want to do is I want to create a new variable called params. And this is going to be equal to parent dot parms like so. All right. And that will return all of the parameters that are actually on this particular node itself. So I'm going to apply and let's actually print that out just so we can verify it. So we're going to say for parm in params, I need another a there. All right. Let's just print, let's say parm dot name, parm dot name. All right. That'll give me the actual internal name for each one of the parameters. So I'm going to hit apply and then go to the Python shell over here and let's actually hit the button. And look at that. It actually prints out all of our parameters. You can see at the very end, we have our parameters that we included, but we're getting all of the parameters for this particular node all the way up to all the transform stuff. And that's because what we've done is we've really just hidden all these parameters are still available, right? For this particular node. And so we're printing out all of these particular parameters. So what we need to do is we need to check to see if they're disabled or visible or hidden, right? And so to do that, we need to write a little bit more of a check. So we need to see if certain particular parameters disabled or not. All right. So we're going to come down here. We're going to say if not harm dot is disabled. All right, then let's print out the particular name there, hit apply. And let's go and check to see if that actually works for us. All right. So I'm going to export prams. And you'll notice that we still get all of those parameters. So what we need to do is we actually need to utilize a different function here. And that is the function that says parms in folder. All right. And so that means this allows us then to from a Python standpoint, look at all the parameters that are just inside of a particular folder. All right. And this is a great way to keep all your stuff organized. So I'm just going to put in a new folder and drag and drop all my parameters into there. And I'm going to call this my parms for the label. All right. Hit apply. And there we go. So then what we need to do is we need to come over here and rather than just get all the parms from the parent node, we need to change this to parms in folder. And then for the argument here, we need to pass a tuple of names. In this case, I really just want to check the one. So that one is called my parms or prams, like so. All right. So we can get rid of this if check here, because that's still printed out everything. All right. So we actually just tab in appropriately there. All right. Hit apply. So now let's make a little space down here. And I'm going to hit export parms. And there you go. So now you can see that we're getting just the parameters that we're interested in. And while I'm at it, why don't we add some values in here? And we'll say hello, Houdini. Like that. Very cool. All right. We also want to make sure that we don't export the button. All right, we don't want to export the button down here. And so what I need to do is I just need to put another check and just make sure that we don't equal that particular name. All right. And that name is export prams. So I'm just going to copy this guy, go back to the scripts tab and let's come in here. I'm going to say if parm.name, let's do this. So parm.name does not equal this particular parameter, then let's print it out. Like so. So I'm going to hit apply. And then there you go. So now we get just those three parameters that we created. Awesome. Okay. So now what we want to do is we want to export all this to a JSON file. All right. And so to do that, we need to set up our data structure. All right. So I'm going to create a new dictionary called data. And it's just going to be an empty dictionary for now. And then I want to add my first key into that dictionary. So I'm going to say data dot, we'll call this parms, like so. And then I want to initialize that to an empty array. All right. So basically we created a new dictionary. Then we added a new entry into that particular dictionary called parms. And then we initialize that as an empty array. So then with that done with for every single param or parameter that we have here, what we want to do is we want to write it to a JSON file. And so we need to build up our data first. All right. And so the first thing I want to do is I want to get the name. So I'm going to create a new variable called name. And then I'm going to initialize that to parm.name. All right. So I'm just setting up the data that I want to insert into these arrays here, these empty arrays in our data structure. And then I want to call or make a new variable called value. And I'm going to say parm dot eval, that'll get the actual value out of there. All right. And we also need to make sure that we convert this over to a string. We'll have to convert it back when we read it back in. I'll make some more videos about reading stuff back in for both text and JSON files. For now, I just want to focus on writing to these particular file formats. All right. So now I have these two variables set up. All we need to do is we need to basically say data dot params or parms, like so. I'm going to say append. So I'm going to append it. And then I want to open up some parentheses. And then we want to add a new dictionary basically in there. Okay. And then inside of that dictionary, I want to give my keys. All right. So I'm going to say name. That's the first key. That's going to be equal to name or this particular variable right here. Then we're going to do a comma. And then our second entry is going to be value. All right. And we need a colon. And then we'll initialize that to value. And you don't need the colon or the comma for the last one. Cool. So now we have our data structure. Awesome. And what we need to do now is come all the way back over here, just make sure we're tabbed in correctly. We can also just go home and then just tab in one more time like so. So now we actually need to write to the JSON file. All right. And so what I'm going to do is I am going to say with open. So we want to open a new file. All right. There we go. Just need one space. And I need to give it a path. So in this case, let's see here, I want to create a new folder on my desktop here. And let's just do this. We'll call this JSON files like so. We'll dive inside and I'll get this path. Now, you know, if you're making this, you know, real production tool, you're going to want to manage your paths appropriately. Okay. So we're going to open up a new file and make sure all these guys are set up as forward slashes just to be safe. There we go. Again, like I said, you're going to want to, you know, handle your paths a little bit more dynamically. And we'll call this params.json. And then I want to set the second parameter here or second argument, I should say, to write. So we just put a w in there. And it's getting kind of long here. There we go. And I'm going to open or open that as a particular name. So I'm going to call this my out file. There we go. So pretty standard term for that stuff. All right. So now we've done that. All we need to do is when you say JSON dot dump, or we're going to basically save it to this file, we're going to take all the data that's inside of this data variable here, we're going to dump it into the file. So we're going to say data, we're going to give it the out file. And then I also want to do an indent equals four, that'll just format the file appropriately. All right. So with that, we should get a file, a JSON file. So I'm going to apply. And then let's hit export parms. And we get an error. Usually happens. And you just need to go and check to make sure that everything is set up appropriately. And it looks like it's because there's a little dot right here. You don't need to do that. Let's hit apply. And let's export again. And we'll get another error. You know, it happens quite often. And it looks like I just, I am totally into the dot notation here. I switched back and forth between C sharp and C plus plus and Python quite often. So that's why I'm doing that. You don't need the dots because we're basically adding a new or accessing the key value from a dictionary there. So there we go. So now we got it. And there's our params.json. Let's actually open this up with the code. If I can, let me actually open code. Studio code. And let's just open up a file here. So let's go to my desktop. And let's open that guy up. There you go. So now we have all of our values. How cool is that? I just wrote a JSON file from our HDA. And it's, you know, as easy as that. And let me actually pop that open for you guys one more time. So you can just see the whole code there. Let me actually open this up. Alt E will open the whole thing up there. So you can see all that. It's actually not too bad. There we go. So I'll leave that up there for a second. So anyways, in the future videos here that it will most likely be coming next week, I will show now how to read all this data back in for both text files and JSON files. And then also how to use it inside of your HDAs to either set the parameters or, you know, even if you're working with other data, maybe it's not parameters. You're saving out other types of data. So you want to be able to read all that stuff back in. Okay. That's what I wanted to show. Thanks so much.