How can I create a triangle mesh in an .ifc file from scratch in python?

397 views Asked by At

I am new to working with .ifc files in python. What is the best way to create a triangle mesh when I have two arrays - one with vertices and one with faces - in a new .ifc file and how can I do this with python with the ifcopenshell package?

I have searched the documentation endlessly and was not able to find it. I would be very thankful if someone can point me in the right direction.

I want to have a similar script like this but instead of creating a wall I just want to create a triangle surface https://blenderbim.org/docs-python/ifcopenshell-python/code_examples.html#create-a-simple-model-from-scratch. I however have not found the right "ifc_class" with the corresponding parameters for that.

1

There are 1 answers

2
Andy Ward On

If you're targeting IFC4 (and above) you can use IfcTriangulatedFaceSet which is specifically designed for a triangulated surface such as this.

Here is an example for creating an a triangulated face set with Python and IfcOpenShell (sample data from documentation):

ifc = ifcopenshell.file()
ifc.createIfcTriangulatedFaceSet()
tfs.Coordinates = ifc.createIfcCartesianPointList3D( ((0.,0.,0.), (1.,0.,0.), (1.,1.,0.), (0.,1.,0.), (0.,0.,2.), (1.,0.,2.), (1.,1.,2.), (0.,1.,2.)))
tfs.CoordIndex = ((1,6,5), (1,2,6), (6,2,7), (7,2,3), (7,8,6), (6,8,5), (5,8,1), (1,8,4), (4,2,1), (2,4,3), (4,8,7), (7,3,4))
tfs.Closed = True
ifc.write('testTFS.ifc')

If you need to support IFC2x3 (which doesn't have the above entity), you probably want IfcShellBasedSurfaceModel - a more generalized entity that can perform the same thing.