Last active
June 15, 2021 11:51
-
-
Save simonreeves/e50137d2f2e8a6cc85b29ceec02dda20 to your computer and use it in GitHub Desktop.
node buddy #houdini #python
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
""" | |
Keep a node close to its buddy whenever the buddy is moved | |
- uses event call back which is only persisstant in session :( | |
""" | |
# create geo | |
geo = hou.node('obj').createNode('geo') | |
# create two nodes | |
mat = geo.createNode('material') | |
matnet = geo.createNode('matnet', 'materials_buddy') | |
# define the method the callback will call | |
def node_moved(event_type, **kwargs): | |
matnet.setPosition(kwargs['node'].position() + hou.Vector2(2, 0)) | |
####### | |
# this isnt persistant so we need to do something to save it in the hip | |
# save this buddy to the node in its userdata | |
mat.setUserData('bee_buddy', matnet.path()) | |
# when scene is loaded in 456.py | |
# check nodes for buddys | |
for node in hou.node('obj').allSubChildren(): | |
buddy = node.userDataDict().get('bee_buddy', False) | |
if not buddy: | |
continue | |
print('{} - {}'.format(node.name(), buddy)) | |
# add event, but need to customise the function! hmmm | |
node.addEventCallback((hou.nodeEventType.PositionChanged,), node_moved) | |
# add event callback when the position of the mat node has changed | |
mat.addEventCallback((hou.nodeEventType.PositionChanged,), node_moved) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment