0

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.

Nils
  • 3
  • 5

1 Answers1

0

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.

hlg
  • 1,321
  • 13
  • 29
Andy Ward
  • 324
  • 2
  • 7
  • Thank you for the answer! I tried it with ifcopenshell in python in different ways but sadly did not get it work. Do you have any knowledge how the python code to create one simple IfcTriangulatedFaceSet would look like in python with a package like ifcopenshell? – Nils Jan 18 '23 at 17:33
  • Sorry not in Python - here's an example of how we do it in C# with xbim - it won't be that different in python & ifcOpenshell as it's the same schema each library is building: https://github.com/andyward/Obj2Ifc/blob/a9ec47b12d8939fbf5d9afb0ba8752743f43305c/Obj2Ifc/Obj2IfcBuilder.cs#L161 – Andy Ward Jan 19 '23 at 11:55