According to the documentation, materials can be applied to Drawingelements. Thus, a material can be applied to an instance, a group, a face, etc.
I’m asking myself about the best way to retrieve all the materials applied to a specific definition. The simplest idea is iterating over all the faces and retrieve both back and front materials, but this process may be slow with high polygon objects.
We can find materials at different levels, for example at instance level (objects with one single material) or at group level (group of faces with a single material) that can help making the process faster. On the other hand, edges are also Drawingelements, so theoretically we should also iterate over them to obtain possible materials, which may make the process even slower.