Jump to content

Can a Null Contain Attributes?


Atom

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...