how can i put a list of strings into a detail attribute with python?

   4831   4   0
User Avatar
Member
617 posts
Joined: Aug. 2008
Offline
I am working in a python node, and created a list of strings that I will be using in the next node (attrib wrangler).
maybe I can store it in a different way?
User Avatar
Member
477 posts
Joined: July 2005
Offline
Hi,

yes you can use array attribute types, which are supported in the VEX context. For example an array of string is supported to be exported back from python. The only thing you have to do, is adding and setting a global attribute.
Check attached file example for the syntax.

Attachments:
py_set_attr.hipnc (59.9 KB)

User Avatar
Member
617 posts
Joined: Aug. 2008
Offline
strange I was doing
geo.addAttrib(hou.attribType.Global, “connections”, ) and did work, but didn't work with strings,
thanks
User Avatar
Member
477 posts
Joined: July 2005
Offline
Yes,

it seems that geo.addAttrib can't handle strings. If I put an array into it, it creates as many attributes as array size. For string array it will be empty.
User Avatar
Member
45 posts
Joined: April 2016
Offline
Here is an example that worked for me.

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

some_list = ["blah","blah"]
geo.addArrayAttrib(hou.attribType.Global, "data", hou.attribData.String, tuple_size=1)
geo.setGlobalAttribValue("data", some_list)
  • Quick Links