 Howdy guys, hope everyone's doing well and staying safe and healthy and all that stuff in this video What I wanted to do is talk about how we can export out all of our multi-parm Data here to a JSON file. All right, just kind of adding on to all the other JSON exporting Tricks and tips that we've been doing lately in our Houdini Python projects video series And so what I have here is I've gone ahead and set up an HDA and I Created a multi-parm which allows me to add as many boxes and place them wherever I want and color them Whatever I want on a per instance basis, right? So if I add another one, you can see I get another box in here And what I want to do is just move this guy over here Maybe this is where I want this particular box to go and then I can also control the Z position as well And we can also give it a custom color now the cool thing about this is What if I want to use this data somewhere else or let's say I want to you save it out So I can re-import it somewhere else in a different hip-file or a different HDA Basically, you know reset all this up In a different HDA. Well, what we're going to do is we're going to cover how to export all this to a JSON file So I set this up here So it exports to a JSON file if I go over to code now You can see I have that new entry right here. And so I'm exporting out all the blocks From the multi-parm into a JSON file so I can save all that data out. It's very useful All right, so yeah, let's get into recreating all this now Okay, so let me hide this guy here for now and let's create a new geometry object And I'm just going to call this my multi-parm test 2 and What I want to do is go make a digital asset out of this and I'm just going to leave it out with the Default name for now. This is really just an example here. So I'm just going to save it into This particular HDA folder. All right, so hit accept and accept There we go. We'll just draw our spare parameters because we don't need them and Let's hide our default UI like so there we go Okay, so the first thing I want to do is I want to set up a couple folders So this first one is going to be the export folder We're just going to have a button in it That allows us to execute the export and then we also want a file directory So the location of where we want to send the file. So I'm going to call this file dirt And we'll call this file directory for the label and for the button. We'll say export data We'll say export Data there we go. Cool All right, so then the next step that we want to do is create a Multi-parm block so to do that you just drag out a new folder and you set the folder tight to a multi-parm block list And this basically will set it up as a multi-parm You'll get a different look here where you can go and start to add instances now because we haven't Created the definition Right forward this multi-parm is you're not going to get anything when you hit this little plus button But now we have a multi-parm in place What I want to do is I want to name this To something like blocks you can name it whatever you want. So we'll call blocks It's important to name this just so you can get access to that stuff. So now it's called blocks All right, and in here what I'm going to do is I'm going to add Float vector 2 and a color to this These will be our two properties that allow us to control the position and the color. So I'm gonna say position and This will be color Like so Very cool All right, so with that in place You'll notice now when you hit apply That we get a little hashtag at the end of here and that's because all these guys will get a particular name Assort, I should say an ID Associated to them and so this hashtag really is just a placeholder for Whatever instance number this is right. So now when we hit plus over here, we have one instance So this big hashtag will be replaced with a value of one All right, so this is position one color one and then if we had another one we have position two and color two Okay, so you can get rid of these guys by hitting a little X button You can also add once but I tend to stay away from that. I just use this guy right up here Just because I like to you know, keep them all stacked appropriately All right, so with that done Let's go and set up our network inside of our node. All right, so to do this We're gonna use a for each number loop All right, this will allow us to control What happens with each of those particular blocks? I'm just gonna feed in a null to start with and then I'm gonna create a box over here and What I'm gonna do is add in a merge node and So we'll merge in a box every single time we create a new instance All right now currently the for loop is set up with the default of iterations 10 and we actually want to Come up here. We want to copy this blocks ID right here that number, so I'm just gonna say copy parameter By right-clicking on it and selecting copy parameter, and then we're going to paste relative reference That gives us the amount of iterations. All right, so at this point what I want to do is I want to Allow the user to control the position. So this is gonna become our position node and we also want to control the color so I'm gonna drop down a color node here and Now we need to set up some expressions in here some hscript expressions in here to Actually control it so we need to get the values from each one of these instances So that way we have control over each box that we create All right, and to do that We actually need to set up Our expressions. All right, so what we're gonna do is we're gonna say ch all right for channel And then we need to do the string cat function this allows us to concatenate two strings together and Right off the bat. We know that we want to get for this one the position So we're gonna get position and now you'll notice that we have access to position 1x. All right So that position 1x is this position 1 right here. All right You'll notice that Houdini will add on that one when you search through the list and this little IntelliSense stuff right right here. So position 1x position 1y So let's do this. We need to select position 1 but we can't do that straight up because we need to actually get the iteration from our Loop count right up here or for each count. So I'm gonna call this my loop data and Then what we need to do is inside of the string cat function. We need to get that iteration value So we need to reference the loop data node Then get the iteration Value and then we need to add one onto it. So plus one And now right off the bat, that's not going to actually work and that's because If we actually middle mouse this we're just getting zero right and if we actually come over here It says it can't evaluate the expression. There's a bracing area in there. So let's actually take a look at this really quick here and This guy is going to So we need to get rid of this guy right there first off There we go. All right, so we got rid of the air. Let's send extra parentheses there Now what's happening is it can't actually access the value because what we're actually evaluating to is just position One right so this detail expression here is returning to us a value of one because we only have one instance and so really this String cat function will evaluate to position one where when you saw it when we were using the IntelliSense It was position one X which means we need to do another string cat. So we need to do a string cat again around this whole thing here Like so and we need to add on the X Like that and apply and there we go and accept So now if we were to go up here and test our X direction, you can see we have control over that So a little confusing at first you just have to do two string cats for this particular type of parameter that float Vector two and then for the z direction. I'm going to use the y value so that position y So now I should have control over both the z position here. Yep, and the X position All right So now what we need to do is we need to copy this I'm just going to copy this because I don't want to have to type that all again And we just need to get the RGB values from that color parameter. So rather than position we're going to do color and This is going to become R like so All right, so I have control over the Red channel, let's copy this and we'll just replace this with the G and replace this guy with the B channel There we go. So now we can control the color right so I can make this guy a blue Awesome. So now we have control over, you know, all of our instances of the boxes so I can put these guys wherever I want Now and color them whatever I want as well So let's do one more instance here. Just we have three and I'm just going to move this guy over here And maybe we do this like that And then we'll assign like a green color to this Awesome. So now we have our HDL setup So always good idea to save your node type at this point And what we need to do now is write a little bit of Python to get this to export to a JSON file now All right, so let's actually go and just assign our file directory up here I'm going to come up here and I am going to Select a folder that I created on my desktop. You can send the file wherever you want So you can see now we have the file directory And now we need to do is we need to start doing our Python So the first good step for this is to create a go to the scripts tab and create a Python module And we're going to create our first function. Actually, we're going to only create one function And I'm going to call this export block data And we're going to pass in our quarks dictionary. So we can have access to a bunch of information about this HDA All right. So in here, I'm just going to put a print statement in here to make this work I'll just type in working like so Just to make sure that I'm I'm actually firing this off with the button So then in our parameters tab, I'm going to go to the button now And I'm going to make sure that my callback script is set to Python And I'm actually going to utilize the who dot phm All right, so that's a new one. I found that in the documentation. It's just a shorthand for the Who dot PWD dot HM function, right? So it's just a faster way to do this And then what we need to do is just call our export block data So we're going to call export block data and pass in our quarks That's a global dictionary that side effects or hooding crates for us Awesome. So with that done, let's go test this out So I have my Python shell open and if you don't have it open you can always just go to a new pad Pain type here and just open the Python shell from there And you can do that anywhere. So wherever you want to put your Python shell All right, let's hit export data and you can see we are working awesome All right. So hopefully that made sense I'm just using the new this new function you might have seen if you watched my other videos I've been using the who dot PWD. So I just discovered this recently Awesome. So let's go back to our scripts tab and start typing in our code So the first thing that I know I'm going to need is the JSON module because we're going to be Exporting to a JSON file. And then what I want to do is get access to the parameters on this HDA. So I need to get this particular instance of the HDA and to do that, I'm going to type out a variable name HDA and then I'm going to use utilize that quarks dictionary and pull out the node Option from there. So that gives me the HDA and you can verify this if you print the HDA dot name like so So let's hit apply and hit my export button and it's not parent. It's print There we go All right, let's hit that button one more time. There we go. So we have a multi-parm test too. Awesome All right. So the next thing we're going to need is I need to know the number Of blocks or number of instances right here, right? So I want to get this number So that's pretty easy to do all we need to do is say HDA Dot parm and we want to get The value from that blocks folder. All right, so we use this blocks name right there And then we'll pump that guy right into there and I want to say eval as int So I know that I'm evaluating this to an integer value. So let's hit apply and let's do a print num And apply one more time Hit export data and we get three Very cool All right. So the next thing we need to note is our instances. So All of these particular parameters here are just instances From our initial definition right here, right? And so to access that inside of Python inside of Udini here, all we need to do is say HDA dot parm And make sure you spell it correctly And we want to get the instances from our blocks folder And we just use the multi parm instances function. So multi parm instances function All right, so if I were to go and print out my instances now You will get a bunch of data. So let's do this. We'll say export data And there you go. We now have access to all of the individual Parameters so position one x position one y so on and so forth Cool, so now we can actually loop through all this stuff But before we do that before we get into all the loops and stuff that we need to put in here Let's get the directory All right, so we're going to say hd a dot parm and we're going to get blocks Or actually not blocks. We're going to get a folder. That's what I called it. I believe Yeah, a folder very cool And I'm going to say eval as string like so And let's just verify that that is working. So print dur We'll hit our button up here. Yeah, so we get our location Very cool All right, so now we're going to work on our loops. So the way this works is we need to Loop through the number of instances that we have so we're going to use utilize this number Option here because I want to loop through each instance or each block And basically sort out the data So I need to do a for i in range And that range is going to be our num like so All right, so now we're looping through each one of those guys And then each time we loop I want to say for instance. I want to check the instance in the instances like so So for each one of the instances That's right here. So these are all the instances right here In this in this list We're going to look at each instance and I actually need to check the name to to verify that it's a part of the current block that we're on Okay, and so to do that We are going to then in that instance. We're going to check to see if the instance dot name If it has the current I value the current iterator Then we're going to we're going to keep it right so we're going to say if instance dot name dot find Like so and I need to do it str i plus one so we convert it to a string Is greater than or equal to zero like so Then we can get the value. So we're going to say name is equal to instance dot name And the value is going to be equal to the instance Dot Eval so just a generic eval Because we might have strings and floats and ints and all of this and I really just need a generic way to get the value out of that All right. So with that done, uh, let's let's go and verify this. So I'm going to say print We're going to say name plus let's do colon there with a space plus a value All right, and then at the very bottom here Let's go down here really quick. I just want to add an empty space So I'm going to say print and we're going to do a couple of dots Then a backslash and for a new line. I just want to see each individual blocks data, I don't want to see all the blocks All right, so let's make some space over here in our python shell and hit export data and Oh, we need to make sure we actually export or just print this to a string. There we go All right, let's hit export data. There you go So now you can see we have individual blocks. So we're getting each instance The data from each instance there. So we have all the ones all the twos and all the threes Very cool All right, so now we've got that it's time to export this out to a json file All right, so we need to create our data block or data Dictionary, I should say So this is what I usually do for all this and so I'm going to put in a first entry called blocks And this is going to be equal to A empty array basically And then we need another type of data block here and I'm going to call this block data All right, so then this is going to be equal to an empty dictionary. That's the curly braces So then we need to fill our block data with all these values here. So I'm going to say block data I'm just going to block data. There we go. And the name is going to be name and it's going to be equal to value like so Let's get rid of all of our prints here. We don't need those anymore And then once we fill our block data with a parameter at the very end here for each Basically for each of those loops there. All right, what I want to do is I want to Append it to the data dictionary So I'm going to say data blocks Dot append And we want to append our block data that we just created There we go All right, so then at the very end here, let's just print out our data Just to verify that we're actually getting a bunch of data there All right, and so let's make some more space here in our python show And do export data and look at that We now have in each array We have all the data that we need on a per block basis Very cool. So now we need to export this to a json file. And so to do that, I'm going to Create a path based off of our dir. So we're going to say dir plus Then whatever, you know file name you want to give it and obviously you can you can come up here and create another String parameter so you can let the user Determine the name of the file in this case I just want to I'm just getting this up and writing. So I'm going to call this multi palm blocks Dot json So I'm just going to hard code it in there for now All right, and then we need to create our json data. So we're going to say json data is equal to json dot dumps And we are going to put in we're going to dump in our data I'm going to change the indent to equal to four and we also need to sort our keys So let's do sort keys is equal to true just so it's readable And then finally we need to write the file. So we're going to say with open All right, so that's how we open the new file We're going to send in the path And we're going to set it to write so two quotation marks single quotes and a w and we're going to say as f so we're going to Use this function inside of this f variable here And all we need to do is say f dot write And we'll write our json data to that file And with that that should be Everything it looks good. All right, so apply And let's go and test this out now hit export data And let's go find our folder on the desktop and open that up inside of visual studio code Yeah, so we have multi palm block Let's open that up and there we go. We now have our three Blocks written out to a json file from our multi palm And just to verify let's add one more instance there. So I don't need this anymore. So apply and accept Let's add one more And let's uh move it around over here somewhere Let's put it over there. We'll give it like a pink color And then hit export data Let's go back to visual studio code and there you go So we have the the fourth instance right there All right, so that's basically how that works. That's how you get access to the multi palm instances and how you can control it on a per block basis All right So hopefully you guys like the video. Thanks so much