Jump to content

Changing parameters from a python script


Yalf

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!

Link to comment
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.

 

Link to comment
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?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...