Python dictionaries to detail attrib [SOLVED]

   162   2   0
User Avatar
Member
88 posts
Joined: 11月 2019
Offline
Hello!
I might be missing something super basic but I am not getting this to work, it just returns an empty dictionary attribute. In a python sop:

node = hou.pwd()
geo = node.geometry()

data = {
    "key1": 'a',
    "key2": 'b',
    "key3": 'c'
}
geo.addAttrib(hou.attribType.Global, 'data', data)

Does anyone have a clue of what I am doing wrong? According to the documentation, dict type is supported.
Edited by Cicuta - 昨日 07:02:17
User Avatar
Member
88 posts
Joined: 11月 2019
Offline
node = hou.pwd()
geo = node.geometry()

data = {
    "key1": 'a',
    "key2": 'b',
    "key3": 'c'
}
geo.addAttrib(hou.attribType.Global, 'data', data)
geo.setGlobalAttribValue('data', data)

Apparently for dictionaries one cannot directly set the value just with addAttrib. It also needs setGlobalAttribValue too, unlike with other types.
User Avatar
Member
8837 posts
Joined: 7月 2007
Offline
AddAttrib can only sety the default value of the attribute which mostly only numerical attributes support

So in case you are using addAttrib for other attributes to set "value" you may want to go back and rethink whether you want that value to really be default
Default value is used whenever Houdini has to initialize attribute value for new element, so it's always good for it to make sense rather than being a random value that you needed the elements to be when you created it the first time
Edited by tamte - 昨日 08:25:40
Tomas Slancik
FX Supervisor
Method Studios, NY
  • Quick Links