Node Data Blocks

   1872   3   2
User Avatar
Member
19 posts
Joined: 12月 2013
Offline
Hello!

I was just wondering if anyone ever managed to use the data blocks provided as part of the hou.Node API because I couldn't find any example anywhere?

I can't seem to get them to work at all, e.g.:

>>> hou.node('/').setDataBlock('foo', 'bar', 'str')
>>> hou.node('/').dataBlock('foo')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/opt/houdini/18.0.287/houdini/python2.7libs/hou.py", line 11045, in dataBlock
    return _hou.Node_dataBlock(*args)
ValueError: Unsupported data block type

I did try with a variety of types such as 'int', 'char', and others, but no luck so far.
Edited by ChristopherC - 2020年5月4日 16:34:14
User Avatar
Member
2626 posts
Joined: 6月 2008
Offline
It looks like a bug to me.

You can assign data, but never read it back.
node = hou.pwd()

# This all works.
node.setDataBlock("id","1","int")
node.setDataBlock("name","chris","str")
print node.dataBlockType("id")
print node.dataBlockKeys("int")
t = node.dataBlockType("id")
k = node.dataBlockKeys(t)
print t
print k

#This fails.
#print node.dataBlock("id")

#This fails.
print node.dataBlock(k)
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
19 posts
Joined: 12月 2013
Offline
I'm assuming so too—I just submitted a RFE for it.
User Avatar
Member
15 posts
Joined: 1月 2021
Offline
Hi, did you ever hear back about this?
From some testing I think you have to pass `None` for the 3rd argument and in python 3 the value should be a `bytes` type (I think a `str` type in python 2).
E.g.
> n.setDataBlock('id', '1'.encode(), None)
> n.dataBlock('id')
b'1'
> n.dataBlock('id').decode()
'1'

> n.setDataBlock('test1', pickle.dumps({'a': 1}), None)
> pickle.loads(n.dataBlock('test1'))
{'a': 1}
  • Quick Links