IFC Brep from FreeCAD
I'm trying to get a brep from freecad and add it to a IFC.
It seems to be working, or at least i can create
#116=IFCSHAPEREPRESENTATION($,'Body','Brep',(#115));
#117=IFCPRODUCTDEFINITIONSHAPE($,$,(#116));
However, in BlenderBIM nothing is displayed.
What am I doing wrong? Attached my files
Her's my code:
import ifcopenshell.api.geometry
import ifcopenshell.util.representation
import ifcopenshell
import ifcopenshell.geom
import ifcopenshell.api
import ifcopenshell.api.root
import freecad
import FreeCAD as F
# FreeCAD
doc = F.open("cube.FCStd")
obj = doc.getObjectsByLabel("Body")[0]
obj_string = obj.Shape.exportBrepToString()
# IFC
model = ifcopenshell.open("empty.ifc")
element = ifcopenshell.api.root.create_entity(model, ifc_class="IfcFurniture")
ifcopenshell.api.geometry.edit_object_placement(model, product=element)
product_definition = ifcopenshell.geom.serialise("IFC4", obj_string, False)
product_definition = model.add(product_definition)
print(product_definition)
element.Representation = product_definition
model.write("cube_test.ifc")
Comments
Work if import back to FreeCAD ?
@paullee
No, if i import the IFC in FreeCAD, the geometry also doesn't show
Apparently, you doesn't export correctly somehow. I export in FreeCAD and re-import and it works :)
Below are codes generated in FreeCAD console, for reference:-
I know how to export a IFC from within FreeCAD.
However, I'm trying to export it as a Brep instead of a Mesh to avoid a high Polygon count on more complicated parts.
Oops, missed that point.
From FreeCAD, export it as Brep by checking the option at Edit - Preference - Export IFC dialog box. You may also check 'User IfcOpenShell Serializer if available'. By both setting, it export and re-imported without problem - both *.ifc attached for reference.
You may have a look at the importers.exportIFC to see how it use IfcOpenShell serialiser.
I have a look at the exportIFC.py, found some lines which seems relevant to you? Seems similar...
Full paragraph :-
Curious why if IfcOpenShell serialiser is used, the *.ifc become 12.3K from the one without the serialiser 3.1K, 4 times as large?
@yorik Have a gap to comment? :)
Just open the two files in a text editor and you'll see why.. The serializer is not optimized for compactness, but on the other hand it recreates a very faithful copy of the brep structure: points -> line -> edge -> wire -> face -> body, everything is there.