Jump to content
Sign in to follow this  
Atom

Can a Null Contain Attributes?

Recommended Posts

Atom    516

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 by Atom

Share this post


Link to post
Share on other sites
Atom    516

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 by Atom

Share this post


Link to post
Share on other sites

 

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×