 Howdy guys, IndiePixel here, and in this video, what we're going to do is we're going to continue our Python learning for Houdini and Specifically in this video, what I want to do is show you guys how to export to a text file All right using one of the buttons on your HDA So if you make a but or make it a an HDA here You have the ability to read out all of the parameters all the data inside of all these parameters And you can actually export this out to a file. So if I hit this export params Button and open the text file that it generates it gives me all the values. So I get one point one four one and one Let's look at that again. There you go. So I get all the values from it if I were to let's actually close that and Let's put in something like ten and two and four There we go, and let's export the parameters again and go find that file Which I'm just writing out to the desktop. You can write it anywhere And we'll take a look at our text settings and there you go. Look at that So we're actually writing data out to the to this text file. So that's what we're going to do throughout this video So let's get started Okay, so let's get started with creating our HDA that actually exports out all of their parameter settings and whatnot. So I actually have a HDA that I've made already and I actually want to expose a couple more parameters So let's go to the type properties here And what I'm gonna do is I'm gonna go dive inside. Let's get going to allow adding editing of contents And let's go and also promote the size here So we're gonna basically export these particular values To a text file and this is useful in this case because we have one That's just a float and then we have one that is also a vector, right? Meaning it has three floats that define its X, Y and Z values. Okay So we're just going to take a look at how we get access to all that data inside of Python. All right, so let's go and Get the process started So what we need to do is we need to create a button So I'm going to drag and drop a button over here And I'm just going to call this some exports and for the label will say export Rams for parameters. All right, these are all of our parameters up here And in that particular button what we want to do is we want to make sure this is set to Python Not each script. All right, because we're gonna be calling some Python from within this particular HDA And that Python needs to go into this scripts area right here All right So what we need to do is we need to add a new Python module to this So we come down to this event handler down here And we go and select the Python module and that will create our Python module for us All right, so to get this started what we should do is we should define a function So we're going to put def and we're going to call this exports params Like so and then put a colon at the end now what we need to do is We need to get access to this particular instance of this HDA. All right So this particular instance that's been created here inside of the OBJ area and to do that We're going to pass in what is called the quarks like so and we need a gene there now This is a special local Dictionary variable that is created for us by Houdini and it passes us a bunch of information about this particular Instance of this HDA. All right, so it'll make more sense once we start to use it All right, so let's go back to our parameters over here And in the callback script for our button what we want to do is we want to say who Dot PWD like so and then we can do you could do HDA module like so or you could just do HM Like that. All right, so that stands for Houdini module And then what we need to do is we need to reference this particular Functional we need to call it I should say. All right, so we're gonna say dot export params and then we're going to pass in quarks Remember that quarks is created for us by Houdini. All right, it automatically populates and it's a Python dictionary All right, so just to make sure that everything is working Let's go back to our function that we're creating here and let's just do a print statement Just to make sure our button is hooked up to our function. All right, so we'll say exporting parameters like so hit apply and To view this let's just kind of put this guy over here I already have my Python shell open But if you don't you can just go hit this guy right here and you can do Python shell like that All right, so now when I hit this button up here my parameter view for my HDA We get exporting parameters So that means we've hooked up our function to this particular button using this particular code right here. All right Cool, so now that we have all of that information. We don't need this particular print statement anymore The things that we do need though for all of this is We need to get access to this particular instance and to do that I'm gonna declare a new variable called parent or parent Like so and this is going to be equal to quarks and Then we need our brackets because remember this is a dictionary and so it has key value pairs And in this case what we want to do is we want to get the node Value and so we're gonna use the key node and that returns this particular node this instance of this HDA right here So now we've got that stored in there. What we need to do is we need to go and get our parameters All right, we need to get their values up here. All right, so let's do that So let's actually go and give ourselves some comments. I'm gonna say I get parent node like so and then we're going to get Parms like that there we go and The first one we want to do is uniform scale. So let's store that. I'm gonna call this uniform scale is equal to our parent Dot parm. All right, so this is basically how we access the parameters over here All right, we access them by their internal name All right, and that internal name is the scale to in this particular case. I didn't name it anything special This is just the name that was generated when I promoted the parameter from the the box node inside of this box Make sure HDA All right, and so this is how we get that that particular parameter. We need to reference it by its Internal name up here. So I'm going to go back to scripts. So we're gonna say parent dot parm We want to get that particular Value all right, so this by itself what this does if you actually look at the documentation for all this here, and let's actually go up to the help here by hitting that little question mark up there and if we do we want to look for Python and We should do Python. We'll do parms. See if it takes us there really quickly And that's actually just taking me to the Python geometry node So let's go up to browser and I'm gonna look for Houdini Python and who that's the main module. So the Python who module and what we want to do Once you go there, it's just type in parm up here. There you go So who dot parm so it's a parameter in a node This allows us to access those particular parameters that exist on a note All right, so let's go back to Houdini over here And let's see what this does that so this gets us the parameter, right? and That returns a parameter It doesn't actually return the value itself. We actually need to utilize the eval. All right, so I'm gonna do eval Like that and that actually gets us the actual value not just the parameter All right, so let's print it just to make sure so I'm gonna do Print and we're gonna do this uniform scale Like so I'm gonna hit apply and Then let's go hit our button. Look at that. We get 1.0 because our uniform scale is 1 if I were to change this Hit the button again. I get 3.17 pretty cool. All right, so now we need to go and get the Size up here. All right, so let's store that so we're gonna say size is equal to parent parm and we want to get the Size Parm over here. All right, and so I'm gonna come back over here and we're gonna say size and we'll do eval All right, we'll print that so it's a print size now This isn't gonna actually work because it's a vector 3 right So if you actually look at the parameters here and go to the parameter here We have a float vector 3 we have to handle these differently But I just wanted to show what the error message will show so if I hit export parms It'll say none type object has no attribute eval and that's just because This float vector 3 parm it can't it doesn't know how to return a vector 3 basically, right? The clue that you have is if you go to channels you can see that it's looking at size x All right, so that's just the way the mappings were working. So let's change this over to size x and Size x and size x for there hit apply There we go. So far to change this You can see we're getting three point three beautiful awesome, so we just need to copy this line right here and Paste it a couple more times. We'll do size y and size z It would be cool if they actually had some way to just do this in one line Maybe they do I just don't know about it But that's how we do all that right there So now we have all of our information That we need to now basically save into some sort of file now. I'm just gonna be writing to a text file. Okay so What we need to do is we need to put a new comment. We're gonna say write to text file and We need to Collect all the lines up together. All right, and so I'm gonna create a new array So I'm gonna say a lines is equal to some empty array like so Okay, and now what I want to do is I want to put all of these particular values in here So I'm gonna say uniform scale Like so and then we're gonna do a size x Like this and I'm just gonna actually hit enter put another comma there. We'll do size y Like so now we'll do size z So we need another comma and there we go All right, we had to apply Well, what we need to do because we're writing this to a text file These all actually need to be converted into a string. All right, and so to do that we use the Sdr, that's how we convert to a string inside of Python All right, so I just need to surround these parameter calls here to a string or just need to use the string to convert the Float value to a string. All right, so let's do that And then we'll do this down here for this guy. Very cool All right, hit apply. So now all these guys are converted to over to strings instead of floats That's one of the cool things about Python is you can do all those dynamic castings without, you know Really having to do a lot of work All right, so all we need to do now is Actually write this to some sort of file. All right, so to do that Most common way inside of Python is just to declare a new variable called f for file, right? Let me say open and We want to give it some sort of path So in here is going to be some sort of path We haven't done that part yet and then we want to do we want to write to it So we do two quotes single quotes and then w for right. You can also do read or wr Both work so right will Automatically write all the lines to that particular file and if there's no file that actually exists It'll also automatically create the file for us, which is awesome All right, so then the next step would be to do f dot write Lines like so and the lines that we want to write are these lines right here and Then we just want to do f dot close simple as that All right, and that just closes the file So we basically open a new file write all the lines and then we close it call it a day basically so let's hit apply and All that looks pretty good except we haven't actually declared any sort of path right so what I'm going to do I'm just going to write this to the desktop right and so I want to get some sort of path to my desktop really quick without having to type it in manually, so I'm just going to do desktop and Let's actually go inside here and Just so I can get the actual path here. Yeah It's like that and let's create a new variable called path And inside of quotes. Sorry about that equals That's and we want to do forward slash this for these guys Now you could do a lot of dynamic padding and stuff like that, but I'm just showing you guys the the general basics All right, and so I'm going to say HDA settings dot txt that's important to include the format All right, cool. So let's hit apply and with that. Let's go and export our primes All right, so then let's go to our desktop All right, so let's hide that guy or minimize it and then here's my file So HDA settings at txt and look at that. We have all of our data written out now. This is actually a Formatting issue. You can see all the values are all in line with each other. That's not what we want So let's cover that really quick before we close out this particular Video and it's real easy. All we need to do is just concatenate on a new line. All right to do that We just do plus Two single quotes like so and we need a forward slash and an end that stands for a new line So we can just copy that Put this at the end of each one of those lines there. Let's actually just get rid of that extra space there Cool. All right, so I'm gonna hit apply and accept because we are done and I'm gonna export primes Go check out my file again Look at that. There we go pretty cool stuff All right, so hopefully that helps you could do this with lots of different types of File formats one of the more common ones is to do text you could use JSON You can write your own File format if you wanted to This also I should note works inside of the Houdini engine as well So you can export stuff out from the Houdini engine if you need data from Whatever scenes you're working on so really powerful stuff. So hope you guys like it. Thanks so much