Assign colour / material to slab

Hi all
I am using the toolkit to create IFC files
I can export a slab which uses a TriangulatedFaceSet as its definition.

I would like to be able to assign a colour to the slab (and probably a material at some point) but I can’t find an example anywhere. I think that I haven’t really fully understood the relationship between the various entities in the format yet.
This is the snippet where I create the slab (At this point I have already created the CartesianPointList, ptList)

        for surf in surfaces:
            triangulatedFaceSet = IfcTriangulatedFaceSet(ptList, surf["index"])
            shape = IfcShapeRepresentation(triangulatedFaceSet)
            productDefinitionShape = IfcProductDefinitionShape(shape)
            placement = IfcLocalPlacement(IfcAxis2Placement3D(IfcCartesianPoint(db, ptMin.X, ptMin.Y, ptMin.Z)))
            slab = IfcSlab(storey, placement, productDefinitionShape)
            slab.Name = surf["name"]
            slab.Description = "My Surface"

Can anyone point me at a suitable example please, and or explain how I create a material and assign it to an object.
Many thanks

Hi @Wyn_Sleeman,

What toolkit?

– Dale

I am using the
GeometryGymIfc c# classes (via Ironpython)

See if this helps.

Outside of the for loop, you would construct a material, something like:

material = IfcMaterial(db, “MyConcrete”)

Then you can can associate it with the slab using the Method Associate
material.Associate(slab)

Materials can have style, but very few viewers support it. You can assign a shading color (there is a more advanced rendering style as a sub class) using something like this.

colourRGB = IfcColourRgb(db, 0.5, 0.5, 0.5)
shading = IfcSurfaceStyleShading(colourRGB)
surfaceStyle = IfcSurfaceStyle(shading)

Then in the for loop, you can create a styled item using this
styledItem = IfcStyledItem(triangulatedFaceSet, surfaceStyle)

Let me know if this doesn’t help you advance further.

1 Like

Thank you JonM - that is perfect