Search - User list
Full Version: Getting list of Attribute Names and Types in Python? HDK?
Root » Technical Discussion » Getting list of Attribute Names and Types in Python? HDK?
goldleaf
I'm trying to get a list of attributes and their type. However, arrays and matrix attributes don't work; only floats, ints and strings are returned by fooAttr.dataType().

I found a workaround for my specific need, but I decided to experiment with inlinecpp. But I can't figure out how to get the name and type of an attribute using the HDK. Anyone have some tips on how I could print out, as an example:


my_vec2_array_attr, vec2 array
fooVector, vec3
etc...

This is what I've cobbled together based on the HDK examples and graham's github repo (thank you graham!!!!).

Thanks in advance!

—————————————–

attribUtils = inlinecpp.createLibrary("attribUtils",
    includes="""
#include <GU/GU_Detail.h>
#include <GA/GA_Attribute.h>
#include <UT/UT_OrderedIterator.h>
""",
    structs=[
        ("StringArray", "**c"),
    ],
    function_sources=["""
StringArray 
getPointAttribArray(const GU_Detail *gdp)
{
    std::vector<std::string>    result;   
    const GA_AttributeDict      *dict;
    const GA_Attribute          *source_attr;
    //const GA_AttributeType    *attr_type;
    //GA_AttributeType          attr_type;
    UT_String                   attribute_name;
    GA_ROAttributeRef           gah;
    
    
    dict = &gdp->pointAttribs();
    
    for (GA_AttributeDict::iterator it=dict->begin(GA_SCOPE_PUBLIC); !it.atEnd(); ++it)    
    {
        source_attr = it.attrib();
        std::string aname = source_attr->getName();
        result.push_back(aname);
        
        GA_StorageClass sclass = source_attr->getStorageClass();
        GA_TypeInfo typeinfo = source_attr->getTypeInfo();
        
        // Debug printing...
        std::cout << aname << "  \t" << typeinfo << std::endl;
    }
    
    return result;
}
"""])
kahuna031
Where's this github? Sounds useful.

Thanks!
Edit: Is it this? https://github.com/captainhammy/Houdini-Toolbox [github.com]
goldleaf
Yep that's it!
graham
It's nice to see people occasionally have use of my repo!

So how Houdini stores attribute type info varies based on what the data is. For example, when we talk about an attribute being a matrix or quaternion, really this just means that the attribute is of N size (9 or 16 for matrix, 4 for quaternion, etc) and then Houdini will add additional metadata to that attribute that flags how to treat the data later on. This is stored in the attribute's Options data which you can thankfully access through Python (hou.Attrib.options()). In terms of an array attribute that's not the same kind of thing (it's more than just how to interpret the data). hou.Attrib.isArrayType() can tell you if your attribute is an array or not and you'd then rely on hou.Attrib.dataType() to determine which kind of array (float, int, string) like any other attribute.

Consider the following test of some various attribute types:
>>> for attr in geo.pointAttribs():
...     print attr.name(), attr.options(), attr.isArrayType()
float_array_attr {} True
tex_attr {'type': 'texturecoord'} False
vec3_attr {'type': 'vector'} False
P {'type': 'point'} False
Cd {'type': 'color'} False
xform_attr {'type': 'matrix'} False
quaternion_attr {'type': 'quaternion'} False

I don't have the time to look through the HDK docs and offer an example of how to get the same info from inlinecpp right now, but you can probably check the HDK Geometry Attribute docs for some more info on how things are defined internally and how you could get at that info.
http://www.sidefx.com/docs/hdk/_h_d_k__geometry__attributes.html [www.sidefx.com]

Hope that helps!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB