The only thing I can imagine is that pythonocc for ifcopenshell was built with a different swig version compared to FreeCAD. Can find out which swig version pythonocc was built for?
An alternative way for using Part.__fromPythonOCC__ is to save the shape to disk and then read it back with Part.Shape.read
wmayer wrote: ↑Wed Jul 03, 2019 5:55 pm
The only thing I can imagine is that pythonocc for ifcopenshell was built with a different swig version compared to FreeCAD. Can find out which swig version pythonocc was built for?
wmayer wrote: ↑Wed Jul 03, 2019 5:55 pm
An alternative way for using Part.__fromPythonOCC__ is to save the shape to disk and then read it back with Part.Shape.read
Ok, I'll give it a try. How do you save a shape to disk ? PythonOCC and ifcopenshell documentations are quite light I struggle to find how to do stuff (I will do some wiki page/blog post about when I will have a better overview about it).
I blog about HVAC / BIM / Energy : pythoncvc.net. If you like you can follow the RSS feed.
I haven't used pythonocc for many years so I don't remember its package structure. But it's pretty much a 1:1 wrapper of the C++API so the class/method names are identical.
In C++ we have the static function BRepTools::Write which needs two parameters: the shape and the file name. So, I guess in Python it's probably BrepTools.Write(occ_shape, "/tmp/shape.brep")
wmayer wrote: ↑Thu Jul 04, 2019 7:36 am
I haven't used pythonocc for many years so I don't remember its package structure. But it's pretty much a 1:1 wrapper of the C++API so the class/method names are identical.
In C++ we have the static function BRepTools::Write which needs two parameters: the shape and the file name. So, I guess in Python it's probably BrepTools.Write(occ_shape, "/tmp/shape.brep")
Thanks a lot for your answer.
I have been able to write to temp file then read it but I still get Segmentation Fault Error. On a second thought it seems logic as it is still the same pythonOCC which write and read the geometry.
It made me realize that I don't need to recompile IfcOpenShell but only pythonOCC because IfcOpenShell use pythonOCC directly. So I recompiled successively FreeCAD and pythonOCC so they are now compiled with the same SWIG version. Unfortunately I still get the same error. Could it be more related to the fact that pythonOCC is built on OCE (OCCT 6.9.1) and FreeCAD built on OCCT 7.3 ?
On a third thought… I realized that Part API has a function to read from file what you probably meant to read shape using this function and it worked !
for space_boundary in (b for b in space_boundaries if b.Name == "2ndLevel"):
outer_boundary = space_boundary.ConnectionGeometry.SurfaceOnRelatingElement.OuterBoundary
occ_shape = ifcopenshell.geom.create_shape(s, outer_boundary)
tmp_file = "/tmp/shape.brep"
OCC.BRepTools.breptools_Write(occ_shape, tmp_file)
shape = Part.read(tmp_file)
face = Part.Face(shape.Wires)
Part.show(face)
But not being able to directly use generated TopoDS is still an issue. According from what I understood from Yorik post it is a bottleneck in IFC importation.
I blog about HVAC / BIM / Energy : pythoncvc.net. If you like you can follow the RSS feed.
Reading back the shape with pythonocc makes no sense. Here you should use FreeCAD's Python API to get the shape. The whole idea of writing and reading the shape is to bypass the direct conversion of the pythonocc wrapper because this apparently fails due to some incompatible OCE/OCCT versions.
Could it be more related to the fact that pythonOCC is built on OCE (OCCT 6.9.1) and FreeCAD built on OCCT 7.3 ?
Of course. It's not possible to use OCE and OCCT within the same application because they are binary incompatible which leads to undefined behaviour.
So you have to make sure to either use OCE or OCCT for pythonocc and FreeCAD but not to mix them.
On a third thought… I realized that Part API has a function to read from file what you probably meant to read shape using this function and it worked !
Just for records. Considering PythonOCC state, there is a better way without using PythonOCC and need to use a temp file. IfcOpenShell USE_BREP_DATA setting without USE_PYTHON_OPENCASCADE produce a geometry object containing a brep_data string parameter which contain the geometry in an OCCT Brep format so we can use :
import ifcopenshell
from ifcopenshell import geom
settings = ifcopenshell.geom.settings()
settings.set(settings.USE_BREP_DATA,True)
settings.set(settings.SEW_SHELLS,True)
settings.set(settings.USE_WORLD_COORDS,True)
settings.set(settings.INCLUDE_CURVES,True) # for stuct
file_path = '/home/hugo/Desktop/FreeCAD--forum/0112--dlubal--ifc/'
#file_path = 'C:\\Users\\bhb\\Downloads\\'
f = ifcopenshell.open(file_path + 'E1--3-Axis-Struc-Export.ifc')
f.by_type('IfcPerson')
#entity = f.by_id(77) # is the first one in this file
#entity = f.by_type('IfcWall')[0] # takes the first found
entity = f.by_type('IfcStructuralCurveMember')[0] # takes the first found
print entity
cr = ifcopenshell.geom.create_shape(settings, entity)
brep = cr.geometry.brep_data
print brep
import Part
shape = Part.Shape()
shape.importBrepFromString(brep)
Part.show(shape)