csdksketchup

how to get the Material of group in sketchup?


I have done iterating through the entities in a group, getting all the faces, and then getting the material of each face. However, if the material belongs to a group, there is no material on the face. How do I get the material of the group in this case? I use the C API.


Solution

  • A face can have a front material (and back material) and still be in a group with a group material. In fact it's very common. In that case, the face material takes precedence over the group material.

    SU_RESULT SUFaceGetFrontMaterial(SUFaceRef face, SUMaterialRef* material);
    SU_RESULT SUFaceGetBackMaterial(SUFaceRef face, SUMaterialRef* material);
    

    In addition, there is a much more direct way to get the material of a group.

    SUDrawingElementRef draw = SUGroupToDrawingElement(group);
    SUMaterialRef material = SU_INVALID;
    SUDrawingElementGetMaterial(draw, &material);