Jump to content

Finding all attributes with prefix


Jan_red

Recommended Posts

Hello all,

I'm currently working on a exporter and I am trying to find all attributes on a point or primitive with a certain prefix and its data.

Currently I can only get the data if I know the attribute name.

So if I can get a list of the attributes somehow i could loop though this list and get all the values. (unless there is a faster way to do this of course)

geo = hou.node('/obj/geo/AnyNode').geometry()
try:
   geo.iterPoints()[0].attribValue("Prefix_Attribute")
except:
   print " attr does not exist" 

I have tried to replace the Prefix with a wild card (*) but to no avail.

So far I have not found any other solution in the documentation.

Any help or suggestions would be most appreciated.

Edited by Jan_red
Link to comment
Share on other sites

Hmm, I have this curse that gives me an answer to my problem as soon as i post a question :P

But I'm not quite there yet though.

geo.pointAttribs()

Seems to get me almost close enough. This seems to give me all attributes on that point witch is good enough.

But it returns a tuple with quite some redundant information in there.

Is it possible to just only get a list with the attribute names? Else I will have to go through the entire string and clean it in order to find the correct attribute name.

Edited by Jan_red
Link to comment
Share on other sites

A couple things:

There is a hou.Geometry.findPoint[Prim]Attribs() function you can use to get hou.Attrib objects for specific attributes right away. Sadly it does not accept wildcards so you have to know the exact name.

You can easily filter your list from hou.Geometry.pointAttribs() using a list comprehension.

attribs = [attrib for attrib in geo.pointAttribs()
                 if attrib.name().find("some_prefix") != -1]

If you want all the attributes at once you can use the point[prim]FloatAttributeValues() function.

attr_names =  [attrib.name() for attrib in geo.pointAttribs()
                 if attrib.name().find("some_prefix") != -1]
for name in attr_names:
    vals = geo.pointFloatAttribValues(name)
    # do something with the values

In general, if you are going to iterate over all the points/prims, using iterPoints[Prims]() is going to be slower than just points[prims](). Also, calling hou.Point[Prim].attribValue(string_name) is going to be slower than passing in the corresponding hou.Attrib object for the attribute.

Link to comment
Share on other sites

Hmm it seems like I am running into some trouble again.

Now I need to find the string of a string attribute on points or primitives.

I would like to do it in the same way as pointFloatAttribValues(name)

Since its extremely fast and gives me a nice list of values.

But for some reason I can not find how to do that for strings. (of course i could traverse through all my points/ prims again but that would make it slow again).

Any idea's or suggestions ?

Edit: ARG ANNOYING CURSE.

Wel I have found some way to do it. Its not exactly the same but it works

attrib = geo.pointAttribs()[attrNr]
attrib.strings()

The downside to this is that it only gives unique strings. And not a nice list for each point.

Edited by Jan_red
Link to comment
Share on other sites

String attributes are different than normal attributes internally: they are what are called index attributes. These attributes create a list of the string values and then store the list index for the required value on each element. This is why you only get unique strings.

Edited by graham
Link to comment
Share on other sites

if you want to get the list of attribute values per attribute :

( in my case below ; each point attrib value has the '_$PT' attached to it .. )

>>> for a in geo.findPointAttrib('attriName').strings():
...     print a
... 
adagio_0
adagio_1
adagio_2
adagio_3
adagio_4
..

if you want to build a string attrib's list , maybe you can try to filter those like this :

( there are 2 string attribs on this geo , beside the P and Pw .. )

>>> list = geo.pointAttribs()
>>> for ele in list:
...     type = ele.dataType()
...     print type.name()  
... 
Float
Float
String
String

.. just playing with the shell .

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...