Reputation: 3
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.
Upvotes: 0
Views: 750
Reputation: 121
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?
The easiest and most straightforward way to do this is to use Mesh Representations. You can specify the vertices and faces as a list of list of tuples and use them to add a representation. Here vertices are the coordinates for your selected vertices and faces represent the indices (starting from 0) of the vertices which join to create a face.
I however have not found the right "ifc_class" with the corresponding parameters for that.
While creating a entity for which you are not sure which predefined ifc class
to assign, you can use the IfcBuildingElementProxy element which is "a proxy definition that provides the same functionality as subtypes of IfcBuiltElement, but without having a predefined meaning of the special type of building element it represents." This class can be assigned while creating the element as element = ifcopenshell.api.root.create_entity(model, ifc_class="IfcBuildingElementProxy")
.
Upvotes: 0
Reputation: 369
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.
Upvotes: 0