 Howdy, guys. All right. So in this video, we're going to talk about importing our data from our JSON file that we exported in the last video for multi-parms. So I want to use that data to populate the multi-parm. All right. So that way we can exchange data back and forth between our HDAs. All right. So let me actually just clear this out here and you can see that I've gone ahead and already assigned a file here. But what we're going to talk about in this video also is how to add a little bit of UX to make things a little bit more informative for users. So without any sort of path in here, if I hit import data, we're going to get this little window here that says it couldn't find the file. All right. So we're going to cover how to do that. Let me assign the JSON file here and then import the data and you can see it actually goes and populates the multi-parm with all of our settings that we exported out to our JSON file. All right. So that is what we're going to do in this video. Let's get started. All right. So let's get started with our import of our multi-parm parameter. So if you remember in the last video, we went through and exported out all of our multi-parm data to a JSON file. What I want to do now is I want to be able to call that information back and basically populate my multi-parm because when I go and drop down this particular node here, I believe I have it in here somewhere. Did I not? Yeah. I didn't actually put it into one of the context menus. So when I drop it down, it's just going to show up with its default first box. Right. And so what we want to do is we want to be able to import that information back in and then repopulate our multi-parm. So let's get that going. It's pretty easy actually. Let's go a lot editing of contents and then type properties because we need to set up a couple things and then do a little bit of Python scripting in here. So I'm going to go to the parameters and I'm going to drag out a new folder. I'm going to set this to a simple folder and I'm just going to call this import just to stick with our naming convention there. And we're going to need two things. We need a file because we're going to import a JSON file. So I need to go and find it. So this is going to be our import file and call this file to import. There we go. The label and then we want a button and this button is going to be what executes the code. So we'll say import data. Say import data. Something like that. All right. So now we've got those two guys all set up. Perfect. And before I go and actually find the file, I want to get some code hooked up here. So I'm going to jump into my Python module that we already set up in the last video. And I'm going to add a new definition, all right, or function. I'm going to call this import parms like so. We're going to pass in our quarks as an argument so we can access the parent node. All right. And I also like to start to separate these. Once you start getting more code in here, it's good to put these little separators in here. So we'll just call this import multi-parm parameters. And then I also like to put in just a big strip on top just to make it nice and clear. All right. So let's get the button hooked up first. So we're just going to say print working like so. All right. Hit apply. And then let's go get that code hooked up to our button just so we know it's all working. So I'm going to use the who module and then phd for, I'm sorry, phm for calling the function on this particular node. You might have seen me actually use the who.pwd.hm right before. You can also do hd a module like so. But I found that there's another one called phm, which is awesome just makes it nice and short. And then we want to hook it up to this particular function here. So I'm just going to do that and then paste in the quarks or type in the quarks, hit apply. And then there we go, we're working nice. Let's make a little space in our Python shell here. Yeah. So now our button is all hooked up. So just a couple ways to get access to the functions that are inside of your hd a module. All right, cool. So the next step here is to import our modules that we need to use. So we're going to do json and os. I'm going to use those guys. I'm going to actually make a little bit of space in here just so I can see probably be better for you guys too. All right, so then I usually go and get the parent node. And so I want to do parent is equal to the quarks. And we want to get the node. And that represents the hd a this particular instance of the hd a. So this guy right here. All right, cool. And then next thing we need to do is get our file directory. All right, so we can say parent dot harm. And that was our import dur, I believe is what I called it. Let's go back and check just to make sure our import file. Okay, let's paste that guy there. And we're going to eval this as a string just to make sure. All right, then we need to get the multiparm. All right, so I'm going to do multiparm. And I really messed that one up there. And the multiparm is going to be equal to our parent dot harm. And that was called boxes. All right, we don't need to eval it as anything, we just need the parameter. All right, so with that information, the first thing that we need to do is basically unpack all of our JSON data. So we're going to use the JSON module to do that. And so before we even do that, let's just check to make sure that the length of the file dur, that variable is greater than zero. All right, because if it's if it's equal to zero, then we don't know we haven't assigned anything to it. And we also want to check to make sure that it is an actual file. All right, so the OS module has the path module, which then also has a is file function inside of it that lets us verify whether it's a file or not. So if we pass both those tests, right, so if we actually have some string data inside of this particular parameter, and that string data is actually a file, and we also need to pump in the dur that we want to check, or the string that we want to check. So if that is actually a file, then we can actually do something with it. So I'm just going to print found file. And then we should also do a check or put in some alternative option here. So if we fail, we should tell the user that, you know, you don't have any file assigned, or I can't find the file, right. And so the who module has a UI module, which then has a display message function inside of it. And this allows us then to give some information. All right, so let's say we couldn't find the file like so. All right, so let's go and test this out now. So we can hit apply. And let's go because I don't have anything in here. So let's hit import data. And like that, we couldn't find the file. There we go. So really nice to put in those kind of UX options there just to give the user a little bit more information. So if we do find the file, let's actually leave that print in there. So let's go and find that JSON file. And let's choose that guy and hit import data. Look at that. We found the file. All right, so we're making sure that we actually have the data to work with. Awesome. So the next step in this process, let's declare our data dictionary that's going to hold all the data that comes from that JSON file. And then basically let's open up the file and get all the data out of that JSON file. So we're going to do a with open. And we're going to open that file there. All right, so we're going to pump that in as F or sometimes I like to do out file. So let's just do that. All right. And so then we're going to say that data is equal to JSON dot load out file. All right, so let's print that just to make sure that we actually have some data in there. So we're going to print our data variable that apply. And let's go and test this. And look at that. We now have all that data back inside of Houdini from that JSON file. Very cool. So at this point now we're ready to then populate our multi-parme. Okay, so let's do another check. We're going to say if the length of data is greater than zero, that means we have some data because we don't have any data might as well just exit out of this whole function and not do anything, right? So we're going to then look for all the data inside of our JSON file. So what I want to look for is this blocks array. So it's an array because it has these little brackets here. And inside of that array are a bunch of dictionaries that house a bunch of values that we want to get access into. All right. And so we want to get those. So I'm going to say blocks. We want to get that array. I'm going to say blocks is equal to data. And we put in let me move the cursor there. There you go. We put in the name of that array inside of the JSON file. All right. So if I were to print this right now, we'd get that same. Actually, let's do blocks. We get the same result as we did when we printed the data variable. Yeah. Cool. So now we have accessed each one of those blocks there. So let's loop through all that data and populate the multi-parme. It's as easy as that. So let's do a four I in range. And that range is going to be the length of blocks. All right. Cool. So then for each one of those, we want to add a new instance to the multi-parme. So when we hit this little button right here, we're just adding a new instance, right? And so we can do that programmatically by using the multi-parme. Well, that's the variable. But then we can say insert multi-parme instance. And then we want to give it an index. All right. So that way we control the index. Very cool. So that basically right there will populate our multi-parme. So let me hit apply. And let's test this out. So if I were to import this now, look at that. I get four new instances, which matches the four instances I have in my JSON file. Very cool. All right. Let's clear this out. All right. And actually, let's do one thing here really quick. Because if I were to keep importing this, you can see it's just going to constantly add on to it, right? What I really want to do is I want to clear that out. So what we can do is we can say multi-parme up here. Dot, what is it? Dot set. Yeah. Sorry. Dot set to zero. I just want to set it to zero. All right. So we just hit apply. And now when I import the data, you can see it only has four in it. And each time I hit that button, it only has four. Very cool. All right. So at this point, now all we need to do is loop through now each of the items inside of each of the array elements, right? So currently, we have access to blocks. And inside of blocks, there's dictionaries. All right. And so I want to get access to each one of the items in here and get the name and the value. Okay. And so there's a really cool way to do this. We can say for name, comma value in the blocks, I, so the current iteration that we're on, and then items. So we can inspect all the items in this particular iteration of blocks. So currently, if I were to say that we're on iteration one, right, or zero, that means we are going to get this particular dictionary inside of that name variable here, inside of Udini here. So that name variable and that value, it's going to populate it with the name and the value for us. So hopefully that makes sense. All right. So at that point, all we need to do is say parent.parm. And the parm that we want to access is the name, and we want to set it to the value just like that. Easy peasy. All right, let's apply and accept. And let's go import our data and look at that. We are set right back up. How cool is that? All right. So at this point, we want to go save our node and match our current definition. And now we have the ability to export and import our JSON files to work with our multi-parms. All right. Thanks so much, guys. Hope you guys liked it. Let me know if you have any other requests.