Last active
August 9, 2022 19:46
-
-
Save jamesrobinsonvfx/2c7d4fdc68edc503e2d07f30f200e2ac to your computer and use it in GitHub Desktop.
Context manager for unlocking/locking parameters
This file contains 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 | |
@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