Skip to content

Instantly share code, notes, and snippets.

@jamesrobinsonvfx
Last active August 9, 2022 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesrobinsonvfx/2c7d4fdc68edc503e2d07f30f200e2ac to your computer and use it in GitHub Desktop.
Save jamesrobinsonvfx/2c7d4fdc68edc503e2d07f30f200e2ac to your computer and use it in GitHub Desktop.
Context manager for unlocking/locking parameters
import contextlib
@contextlib.contextmanager
def set_read_only_parm(parm):
if not isinstance(parm, (hou.Parm, hou.ParmTuple)):
return
# Unlock the parm
parm.lock(False)
# Do user stuff
try:
yield parm
except (hou.OperationFailed, TypeError, AttributeError) as err:
msg = "Unable to set parameter! {0}".format(err)
hou.ui.setStatusMessage(msg, hou.severityType.Error)
pass
finally:
# Lock the parm up
parm.lock(True)
# Usage
fileparm = hou.node("/obj/geo1/null1").parm("file")
with set_read_only_parm(fileparm) as parm:
parm.set("/tmp/test.bgeo")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment