Atom Posted December 5, 2015 Share Posted December 5, 2015 (edited) I want to store some additional data on a Null object using python, however, I discovered that a null has no Geometry() section. Can attributes be stored and retrieved on a Null? Edited December 5, 2015 by Atom Quote Link to comment Share on other sites More sharing options...
asnowcappedromance Posted December 5, 2015 Share Posted December 5, 2015 You can look up the incoming geometry the following way: hou.node('/obj/geo1/null1').inputs()[0].geometry() Quote Link to comment Share on other sites More sharing options...
dedeks3000 Posted December 7, 2015 Share Posted December 7, 2015 user data ??? Quote Link to comment Share on other sites More sharing options...
Atom Posted December 7, 2015 Author Share Posted December 7, 2015 (edited) Actually I just named a stickyNote like my attribute and stored the information in the text field of the stickyNote. def setStickyNoteValue (node, name, value): lst = node.stickyNotes() for item in lst: if item.name() == name: item.setText(str(value)) return # Could not find named stickyNote in list. node.createStickyNote(name) # stickyNote does not exist, let's create it. setStickyNoteValue(node,name,value) # recurse into self for new assignment. def getStickyNoteValue (node, name): lst = node.stickyNotes() for item in lst: if item.name() == name: if len(item.text()) != 0: return float(item.text()) break return None # NOTE: Nulls can not contain attributes so we will store our data in sticky notes. def assignControlValue (node_name, parm_name, ctl_value, multiplier): node = hou.node('%s%s' % (node_path,node_name)) # Path to node which contrains our parameter. org_value = getStickyNoteValue(node,"attribute_%s" % parm_name) # Fetch the original_value in stickyNote. if org_value == None: # See if value exists? org_value = node.parm(parm_name).eval() # Grab the original parameter value. setStickyNoteValue(node,"attribute_%s" % parm_name,org_value) # Store it in the stickyNote name original_value. new_value = org_value + (ctl_value * multiplier) # Create a new value based upon org_value and slider value. node.parm(parm_name).set(new_value) # Assign new value to parameter. Then I can just call. n = getStickyNoteValue (node_root, "my_attribute") Edited December 7, 2015 by Atom Quote Link to comment Share on other sites More sharing options...
MrScienceOfficer Posted December 7, 2015 Share Posted December 7, 2015 Actually I just named a stickyNote like my attribute and stored the information in the text field of the stickyNote. Clever, but... you should really use userData like dedeks3000 suggested, it's much simpler. >>> import time >>> # Get a node instance >>> n = hou.node("/obj/sphere1") >>> # Put a name/value on the node >>> n.setUserData("last_indexed", str(time.time())) >>> # Get the named value back from the node >>> n.userData("last_indexed") 1260572254.21 >>> # Get a dictionary of all name/value pairs on the node >>> n.userDataDict() {'last_indexed': '1260572254.21'} >>> # Accessing a non-existent name returns None >>> print n.userData("foo") None >>> # Remove a value from the node >>> n.destroyUserData("last_indexed") I just pulled that right off here http://www.sidefx.com/docs/houdini15.0/hom/nodeuserdata Quote Link to comment Share on other sites More sharing options...
Atom Posted December 7, 2015 Author Share Posted December 7, 2015 You right, after looking at the link that is much simpler, thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.