Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Houdini Python Cookbook: Difference between revisions

From kunz
No edit summary
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
[https://github.com/kiryha/Houdini/wiki/python-for-artists Python for Artists]
Force the entire scene to cook (all nodes)
Force the entire scene to cook (all nodes)
<syntaxhighlight lang='Python'>
<syntaxhighlight lang='Python'>
Line 36: Line 38:
import importlib
import importlib
importlib.reload(module)
importlib.reload(module)
</syntaxhighlight>
Get the transform of a specific prim
<syntaxhighlight lang='Python'>
hou.node('/obj/asset_stitching/blast28').geometry().prims()[0].intrinsicValue('transform')
</syntaxhighlight>
Python SOP, create a point for every bgeo.sc file in a directory
<syntaxhighlight lang='Python'>
import os
node = hou.pwd()
geo = node.geometry()
geo.addAttrib(hou.attribType.Point, 'file', '')
dir ='/path/to/geo/'
for filename in os.listdir(dir) :
    if filename.endswith('.bgeo.sc') :
        pt = geo.createPoint()
        pt.setAttribValue('file', dir+filename)
</syntaxhighlight>
Python SOP, create a packed disk prim for every bgeo.sc file in a directory
<syntaxhighlight lang='Python'>
import os
node = hou.pwd()
geo = node.geometry()
geo.addAttrib(hou.attribType.Prim, 'path', '')
dir ='/path/to/geo/'
for filename in os.listdir(dir) :
    if filename.endswith('.bgeo.sc') :
        pr = geo.createPacked('PackedDisk')
        pr.setIntrinsicValue('unexpandedfilename', dir+filename)
        pr.setAttribValue('path', dir+filename)
        #pr.setIntrinsicValue('viewportlod', 'centroid')
        #pr.setIntrinsicValue('viewportlod', 'hidden')
        pr.setIntrinsicValue('viewportlod', 'box')
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 19:45, 25 September 2026

Python for Artists

Force the entire scene to cook (all nodes)

for node in hou.node("/").allSubChildren():
    node.cook(force=True)

Print the full path of the current Houdini scene

print(hou.hipFile.path())

Get the version numbers in the filename

hou.hscript('echo -n `opdigits($HIPNAME)`')

What platform is Houdini running on?

hou.applicationPlatformInfo()

List all the environment variables

import os
for e in os.environ:
    print(e, os.environ[e])

Increment number at the end of a text string. This is the algorithm used by Houdini to generate uniquely named child nodes inside a network.

hou.text.incrementNumberedString( hou.getenv('HIPNAME') )

Reload a module, useful if you make some changes to the module.

import importlib
importlib.reload(module)


Get the transform of a specific prim

hou.node('/obj/asset_stitching/blast28').geometry().prims()[0].intrinsicValue('transform')


Python SOP, create a point for every bgeo.sc file in a directory

import os
node = hou.pwd()
geo = node.geometry()
geo.addAttrib(hou.attribType.Point, 'file', '')

dir ='/path/to/geo/'
for filename in os.listdir(dir) : 
    if filename.endswith('.bgeo.sc') :
        pt = geo.createPoint()
        pt.setAttribValue('file', dir+filename)

Python SOP, create a packed disk prim for every bgeo.sc file in a directory

import os
node = hou.pwd()
geo = node.geometry()
geo.addAttrib(hou.attribType.Prim, 'path', '')
dir ='/path/to/geo/'
for filename in os.listdir(dir) : 
    if filename.endswith('.bgeo.sc') :
        pr = geo.createPacked('PackedDisk')
        pr.setIntrinsicValue('unexpandedfilename', dir+filename)
        pr.setAttribValue('path', dir+filename)
        #pr.setIntrinsicValue('viewportlod', 'centroid')
        #pr.setIntrinsicValue('viewportlod', 'hidden')
        pr.setIntrinsicValue('viewportlod', 'box')