Mesh get attributes

Hi,

I would like to use

mesh.get_vertex_attributes(key)

to get all vertex attributes without knowing the ‘names’. As a workaround I used

mesh.vertex[key]

to get the complete dict of attributes. Through the grapevine, I heard that using the get* functions is the preferred way of doing things.

So, how to use the get_…_attributes() functions for the mesh to get the complete information stored on an edge, vertex or face?

hi matthias,

currently, it is not possible to get the entire dictionary of attributes of a vertex like this because the names argument of the function is not optional. perhaps it would also be confusing if the get_ functions in some cases return dictionaries and in others lists.

the get_ functions are intended for convenience, for example in the context of numerical calculations:

xyz = mesh.get_vertices_attributes('xyz')
loads = mesh.get_vertices_attributes(('px', 'py', 'pz'))

the different scenarios i can imagine that accomplish more or less what you ask with the current API are the following:

for key, attr in mesh.vertices(True):
    for name, value in attr.items():
        print(key, name, value)
names = mesh.default_vertex_attributes.keys()
values = mesh.get_vertex_attributes(key, names)

note that in the latter case only the values of attributes that also have a default are returned. there might be cases where the user (carelessly) also stored attributes individually on some vertices and not on others. through this approach you would not see those appear in the result…

hope this helps,
tom

I also admit to using mesh.vertex[key] a lot, and for edges and faces the equivalent forms, especially if viewing someone else’s datastructure, where I don’t know in advance what attributes are on there.

I think using get_vertices_attributes() or any get method could be tailored do the job, but as Tom said, it would lead to a result that will in general, not have all the same attributes present on all vertices/edges/faces that are returned in a dictionary.

I would agree that, sometimes returning a list and other times a dictionary would be confusing if using one function, so it would probably need to be a new function name with a dedicated dictionary as a return, like .get_all_vertex_attributes().