# Mesh get attributes

**URL:** <https://forum.compas-framework.org/t/mesh-get-attributes/36>\
**Category:** compas\
**Created:** [February 1, 2018, 1:28pm UTC](https://forum.compas-framework.org/t/mesh-get-attributes/36 "2018-02-01T13:28:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rippmann](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@rippmann](https://forum.compas-framework.org/u/rippmann)\
**Post date:** [February 1, 2018, 1:28pm UTC](https://forum.compas-framework.org/t/mesh-get-attributes/36/1 "2018-02-01T13:28:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)\
**Post date:** [February 2, 2018, 4:19pm UTC](https://forum.compas-framework.org/t/mesh-get-attributes/36/2 "2018-02-02T16:19:15Z")

</div>

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:

```python
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:

```python
for key, attr in mesh.vertices(True):
    for name, value in attr.items():
        print(key, name, value)

```

```python
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

---

<div class="post-metadata">

**Author:** ![andrewliew](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/andrewliew/32/88_2.png) [@andrewliew](https://forum.compas-framework.org/u/andrewliew)\
**Post date:** [February 4, 2018, 3:48pm UTC](https://forum.compas-framework.org/t/mesh-get-attributes/36/3 "2018-02-04T15:48:02Z")

</div>

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()`.
