HoudiniPython

From cgwiki

Make a general python thing ala maya pymel thing

The python console in houdini is a live command line, which if you're used to maya's script editor, feels a bit limiting. What you want is a sketchpad to write stuff, maybe define a function, all that. This is my best attempt at that. Fiddly, but it works.

In a nutshell, create a OTL with a button to call an internal python script.

Make a digital asset

  1. Create a null
  2. Immediately subnet it
  3. R.click, create digital asset
  4. save n stuff

Make a button to call a script

  1. select the node, cog menu, 'edit parameter interface'
  2. on the right hand panel, shift click on the root node to collapse it
  3. regular click it again to expand it, but now the subfolders are collapsed
  4. click each one, make invisible
  5. create a button, label 'doit'
  6. set the callback script to python mode, and the command to 'kwargs['node'].hdaModule().click()'
  7. apply/accept
  8. r.click node, 'save operator type'
  9. r.click node, 'match current definition' to ensure its all clean and correct.


That odd command there calls the current node, and finds the python module inside, and calls the click function. Time to set that up.

Define a click function

  1. r.click the node, 'type properties'
  2. go to the scripts tab
  3. make a 'PythonModule' section
  4. add a basic click function, eg:


def click():
   print 'hello world'


Once you hit apply/accept, you should now be able to click the button, and see output to the python prompt. You can now code away, after each change hit 'accept', and it'll do your bidding.

Other less fiddly ways to achieve this are via the python editor for shelf buttons, but this seemed good practice to make a button click interface hda thing.

As above, but not as HDA

The supremely fast/lazy version:

  1. Make a null sop
  2. edit parameters:
    1. add a string, make it multi, language python
    2. add a button, python callback is
 exec(kwargs['node'].parm('parm').eval())

Get point attributes from a node

From the node get its geometry, then its point attributes, then the short names of those attributes.

[ x.name() for x in hou.node('/obj/mygeo/mysop').geometry().pointAttribs() ]


To go one further and make a nice list to feed to an attribute delete node, use a join() with a single space, prepend with ^'s, and stick an asterisk on the front:

print '*',' '.join([ '^'+x.name() for x in hou.node('/obj/geo1/mysop').geometry().pointAttribs()])


will return

* ^id ^Cd ^Alpha ^center ^orient ^P ^uniqueId ^materialId

Drag most things into the python window

Do this, and what you drag will be converted into the python text equivalent. This works for nodes, parameters, shelf buttons, most parts of the UI.

Write out mmb error text to file

Handy!

open('/tmp/error.txt','w').write(hou.node('/path/to/node').errors())