Created
January 29, 2020 02:34
-
-
Save BigRoy/3f7b4c7b53482c1dba9a29ade44ba1e5 to your computer and use it in GitHub Desktop.
Houdini 18 Solaris Add and Remove USD Rop node Output Processors with Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import contextlib | |
import hou | |
def add_output_processor(ropnode, processor): | |
"""Add USD Output Processor to USD Rop node. | |
Args: | |
ropnode (hou.RopNode): The USD Rop node. | |
processor (str): The output processor name. This is the basename of | |
the python file that contains the Houdini USD Output Processor. | |
""" | |
import loputils | |
loputils.handleOutputProcessorAdd({ | |
"node": ropnode, | |
"parm": ropnode.parm("outputprocessors"), | |
"script_value": processor | |
}) | |
def remove_output_processor(ropnode, processor): | |
"""Removes USD Output Processor from USD Rop node. | |
Args: | |
ropnode (hou.RopNode): The USD Rop node. | |
processor (str): The output processor name. This is the basename of | |
the python file that contains the Houdini USD Output Processor. | |
""" | |
import loputils | |
parm = ropnode.parm(processor + "_remove") | |
if not parm: | |
raise RuntimeError("Output Processor %s does not " | |
"exist on %s" % (processor, ropnode.name())) | |
loputils.handleOutputProcessorRemove({ | |
"node": ropnode, | |
"parm": parm | |
}) | |
@contextlib.contextmanager | |
def outputprocessors(ropnode, | |
processors=tuple(), | |
disable_all_others=True): | |
"""Context manager to temporarily add Output Processors to USD ROP node. | |
Args: | |
ropnode (hou.RopNode): The USD Rop node. | |
processors (tuple or list): The processors to add. | |
disable_all_others (bool, Optional): Whether to disable all | |
output processors currently on the ROP node that are not in the | |
`processors` list passed to this function. | |
""" | |
original_states = {} | |
prefix = "enableoutputprocessor_" | |
processor_parms = ropnode.globParms(prefix + "*") | |
for parm in processor_parms: | |
original_states[parm.name()] = parm.eval() | |
if disable_all_others: | |
for parm in processor_parms: | |
parm.set(False) | |
added = [] | |
for processor in processors: | |
parm = ropnode.parm(prefix + processor) | |
if parm: | |
# If processor already exists, just enable it | |
parm.set(True) | |
else: | |
# Else add the new processor | |
add_output_processor(ropnode, processor) | |
added.append(processor) | |
try: | |
yield | |
finally: | |
# Remove newly added processors | |
for processor in added: | |
remove_output_processor(ropnode, processor) | |
# Revert to original values | |
for parm_name, value in original_states.items(): | |
ropnode.parm(parm_name).set(value) |
Reload all Houdini USD Output Processor Python modules for easier development.
import hou
import importlib
def reload_all_processors():
"""Quick utility to reload all Houdini USD ROP Output Processors modules"""
# Force reload on all Houdini USD Output Processors
for name, description in hou.lop.outputProcessors():
module = importlib.import_module("husdoutputprocessors.%s" % name)
print("Reloading %s" % module)
reload(module)
reload_all_processors()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To quickly get all the created USD Rop Output Processors on the USD Rop node the trick is to do:
Then to get just their names we can strip of the beginning prefix: