Jump to content
Yalf

Changing parameters from a python script

Recommended Posts

Hello, I am new to Houdini. I am creating a building generation tool.
I want to randomize parameters of my "controller", which is just a null node with parameters, that control the buildings length, height, number of windows etc.
I want to randomize these parameters with a python script last of all nodes in the network. 

This is how I try to do it, but it doesn't work and I don't understand the error.

nrOfWindows = `chs("../controller/nrOfVertWin")`
print nrOfWindows
nrOfWindows = nrOfWindows + 1
print nrOfWindows
`chs("../controller/nrOfVertWin")` = nrOfWindows

Any help is appreciated, thanks!

Share this post


Link to post
Share on other sites

`chs...` is a hscript syntax. It's better to use full python if you're going to use python.

Something like
 

import random

controller_node = hou.pwd().parent().node("controller")

windows_parm = controller_node.parm("nOfVertWin")

windows_parm.set(random.randint(0, 5))

This would randomize between 0 and 5.

 

Share this post


Link to post
Share on other sites

Thank you, this works great!

If I could just bother you with one more question that would be even better!

How do I re-initialize a python node? If I want this random number to change every time I click the python node?
If I change something in the script it will re-initialize, but that is a bit tedious. Is there a better way?

Share this post


Link to post
Share on other sites

You can try forcing the cook of a node with `node.cook(force=True)`. But usually you would make a button that would let the user randomize whatever on demand.

You can also take a look at PDG to make a graph that constructs your assets.

Share this post


Link to post
Share on other sites

Oh right, that sounds great!
Thanks so much for all the help!

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×