SoFunction
Updated on 2024-11-19

An in-depth look at Python in HDA

Event Handler

To create a Python script in HDA, you need to select an EventHandle, which indicates when you want to execute the script commands you're creating now.

On Created (executes the script when the node is created)
If you select this option to edit the Python script, Python will execute the commands in Python when the node is created

Python Model (Python Model)

This item causes the created script to be executed according to the user settings during the use of the

You can use this item to set up parameter prompts for nodes, etc.

On Delete (executes the script when the node is created)

Common methods for Python on Houdini nodes

Set Color Sets the color.

node = kwargs['node']# Get the current node
context = ()# Parent object of the current node
(((0.584,0.776,1)))#Set the current node color

Node Creates a node

try:
  out = ('null','OUT_render')# Create a node from the parent of the current node
  (0,node)# Set the out node input to the current node node
  ((0,0,0))# Set the color of the out node
except:
  pass

Print and Button feedback Print Characters and Button feedback

def CacheGeo():# Create some custom methods in OnCreate that can then be called in the node parameter
  this = ()# Get the current node
  print "\nCaching......!"
  filecache = (() + '/cache_geo')# Get the path to set the cache_geo within the current node to filecache
  ('execute').pressButton()# Get the status of execute on the filecache node
  (((0.584,0.776,1)))# Set node color
  
def ReloadGeo():
  this = ()
  print "\nLoaded successfully"
  filecache = (() + '/report_geo')
  ('reload').pressButton()
  (((0.475,0.812,0.204)))

  output = (() + '/output0')  # Set the path of the output0 node within the current node to output
  geo = ()  # Get the geometry of the output and assign it to the geo (ask for the geometry before you can ask for the geometry attribute on this node)
  print len(())  #printablegeoordinal number

Set these two buttons (cache_geo, report_geo) to call different methods when they are executed, performing different actions

Parameters to invoke PythonScripts

().hdaModule().CacheGeo()

This is the entire content of this article.