Using IfcOpenshell and pythonOCC to generate cross sections directly from an IFC file | IfcOpenShell Academy
Opened this issue · 11 comments
#Using IfcOpenshell and pythonOCC to generate cross sections directly from an IFC file | IfcOpenShell Academy
Original comment by Gareth Boyes on 2015-07-05 17:16:24
Hi
Just exploring Ifcopenshell for the first time and trying to run the examples. It appears that the OCC.Utils module has been deprecated.
Is there a workaround for
section_edges = list(OCC.Utils.Topo(section).edges()) ?
Thanks
Original comment by Gareth Boyes on 2015-07-05 17:16:24
Hi
Just exploring Ifcopenshell for the first time and trying to run the examples. It appears that the OCC.Utils module has been deprecated.
Is there a workaround for
section_edges = list(OCC.Utils.Topo(section).edges()) ?
Thanks
Original comment by thomas on 2015-07-26 16:07:41
Hi,
Sorry for the late reply.
The example at http://academy.ifcopenshell.org/using-ifcopenshell-and-pythonocc-to-construct-new-geometry/ has code for both older and newer versions of pythonOCC.
You can try something like this:
while exp.More():
edge = OCC.TopoDS.topods.Edge(exp.Current())
exp.Next()```
Hope that helps,
Kind regards,
Thomas
Original comment by Wouter Coebergh on 2016-01-13 14:31:03
Hi! for anyone in trouble with the following lines, these fix some issues:
from OCC.TopoDS import TopoDS
wire = TopoDS.wire(wire_shape)
becomes
from TopoDS import topods
wire = topods.Wire(wire_shape)
And:
surface_area = abs(OCC.ShapeAnalysis.ShapeAnalysis_TotCross2D(wire_data_handle, face))
becomes:
surface_area = abs(OCC.ShapeAnalysis.shapeanalysis_TotCross2D(wire_data_handle, face))
Hope this helps anyone!
Original comment by Lukas on 2017-01-19 15:56:13
Hello,
I started using IfcOpenShell and I am amazed by the work taht is happening here.
I tried to run this example as well, but i had a little trouble, hopefully this thread is still somewhat monitored.
First of all the House is not displayed unless the line
>display_shape = ifcopenshell.geom.utils.display_shape(shape)
is included as well, unless I overlooked something?
but the real problem starts when I try to get the intersections between the house and the plane,
the first product in product_shapes (which is the (#35=IfcWallStandardCase('2BvPqvNpvCEhxloyKBrFjE',#5,'South wall',$,$,#71,#49,$,.STANDARD.) class))
throws the exception:
exceptions.AttributeError: 'module' object has no attribute 'BRepAlgoAPI'
I don't really know how to handle this kind of excepion as I just started using python and ifcopenshell, so any help is well appreciated.
Best regards,
Lukas.
Original comment by Lukas on 2017-01-19 15:56:13
Hello,
I started using IfcOpenShell and I am amazed by the work taht is happening here.
I tried to run this example as well, but i had a little trouble, hopefully this thread is still somewhat monitored.
First of all the House is not displayed unless the line
>display_shape = ifcopenshell.geom.utils.display_shape(shape)
is included as well, unless I overlooked something?
but the real problem starts when I try to get the intersections between the house and the plane,
the first product in product_shapes (which is the (#35=IfcWallStandardCase('2BvPqvNpvCEhxloyKBrFjE',#5,'South wall',$,$,#71,#49,$,.STANDARD.) class))
throws the exception:
exceptions.AttributeError: 'module' object has no attribute 'BRepAlgoAPI'
I don't really know how to handle this kind of excepion as I just started using python and ifcopenshell, so any help is well appreciated.
Best regards,
Lukas.
Original comment by Lukas on 2017-01-20 09:30:47
Please disregard last comment (can't delete it myself) the import was disabled -.-
Sorry for the trouble.
Original comment by Lukas on 2017-01-19 15:56:13
Hello,
I started using IfcOpenShell and I am amazed by the work taht is happening here.
I tried to run this example as well, but i had a little trouble, hopefully this thread is still somewhat monitored.
First of all the House is not displayed unless the line
>display_shape = ifcopenshell.geom.utils.display_shape(shape)
is included as well, unless I overlooked something?
but the real problem starts when I try to get the intersections between the house and the plane,
the first product in product_shapes (which is the (#35=IfcWallStandardCase('2BvPqvNpvCEhxloyKBrFjE',#5,'South wall',$,$,#71,#49,$,.STANDARD.) class))
throws the exception:
exceptions.AttributeError: 'module' object has no attribute 'BRepAlgoAPI'
I don't really know how to handle this kind of excepion as I just started using python and ifcopenshell, so any help is well appreciated.
Best regards,
Lukas.
Original comment by Lukas on 2017-01-20 09:30:47
Please disregard last comment (can't delete it myself) the import was disabled -.-
Sorry for the trouble.
Original comment by thomas on 2017-02-05 16:17:32
No worries, it is still good to have your comment as a reference for others encountering similar issues. Indeed Python submodules need to be explicitly and individually imported. Thanks for leaving a message.
Kind regards,
Thomas
Original comment by Siddhesh Chavan on 2017-11-17 11:39:38
How to write IFC-SPF file in PythonOCC?
Original comment by Siddhesh Chavan on 2017-11-17 11:39:38
How to write IFC-SPF file in PythonOCC?
Original comment by thomas on 2018-03-24 16:05:33
For others with similar questions: PythonOCC does have an option to write IFC files. You can write IFC-SPF files using IfcOpenShell, for example as discussed in the ticket you opened on github.
Kind regards,
Thomas
Original comment by geert on 2020-01-23 15:31:57
The following changes did make the code work for me
Imports:
Delete
-
OCC.Utils
-
from OCC.TopoDS import TopoDS
-
from OCC.TopoDS import TopoDS
Add
-
from OCC.ShapeAnalysis import shapeanalysis_TotCross2D
-
import OCC.TopoDS
-
import OCC.TopExp
-
import OCC.TopAbs
And the following edits:
section_edges = list(OCC.Utils.Topo(section).edges())
Becomes:
exp = OCC.TopExp.TopExp_Explorer(section, OCC.TopAbs.TopAbs_EDGE)
section_edges = []
while exp.More():
section_edges.append(OCC.TopoDS.topods.Edge(exp.Current()))
exp.Next()
--
wire = TopoDS.wire(wire_shape)
Becomes
wire = OCC.TopoDS.topods.Wire(wire_shape)
--
surface_area = abs(OCC.ShapeAnalysis.ShapeAnalysis_TotCross2D(wire_data_handle,face))
Becomes:
surface_area = abs(shapeanalysis_TotCross2D(wire_data_handle, face))
Original comment by Gareth Boyes on 2015-07-05 17:16:24
Hi
Just exploring Ifcopenshell for the first time and trying to run the examples. It appears that the OCC.Utils module has been deprecated.
Is there a workaround for
section_edges = list(OCC.Utils.Topo(section).edges()) ?
Thanks
Original comment by thomas on 2015-07-26 16:07:41
Hi,
Sorry for the late reply.
The example at http://academy.ifcopenshell.org/using-ifcopenshell-and-pythonocc-to-construct-new-geometry/ has code for both older and newer versions of pythonOCC.
You can try something like this:
while exp.More(): edge = OCC.TopoDS.topods.Edge(exp.Current()) exp.Next()``` Hope that helps, Kind regards, Thomas
Original comment by Thi NGUYEN on 2021-03-19 10:10:59
Hi,
I'am using pythonocc-core=7.4.0, python 3.7, ifcopenshell (Anaconda3).
I try to extract the faces of slabs using the following code but it gave me a error: 'Geom_Surface' object has no attribute 'GetObject'.
Do you have any idea? i would appreciate it a lot.
Thank you in advance!
Here is the code that i tested
topo = TopExp_Explorer()
topo.Init(slab_shape.geometry, TopAbs_FACE)
faces = []
while topo.More():
fc = topods_Face(topo.Current())
faces.append(fc)
topo.Next()
#Extract the faces of the slab shape
for face in faces:
surf = BRep_Tool_Surface(face)
#Get the plane that represent the face
plane = OCC.Core.Geom.Handle_Geom_Plane_DownCast(surf).GetObject()
Original comment by Gareth Boyes on 2015-07-05 17:16:24
Hi
Just exploring Ifcopenshell for the first time and trying to run the examples. It appears that the OCC.Utils module has been deprecated.
Is there a workaround for
section_edges = list(OCC.Utils.Topo(section).edges()) ?
Thanks
Original comment by thomas on 2015-07-26 16:07:41
Hi,
Sorry for the late reply.
The example at http://academy.ifcopenshell.org/using-ifcopenshell-and-pythonocc-to-construct-new-geometry/ has code for both older and newer versions of pythonOCC.
You can try something like this:
while exp.More(): edge = OCC.TopoDS.topods.Edge(exp.Current()) exp.Next()``` Hope that helps, Kind regards, Thomas
Original comment by Thi NGUYEN on 2021-03-19 10:10:59
Hi,
I'am using pythonocc-core=7.4.0, python 3.7, ifcopenshell (Anaconda3).
I try to extract the faces of slabs using the following code but it gave me a error: 'Geom_Surface' object has no attribute 'GetObject'.
Do you have any idea? i would appreciate it a lot.
Thank you in advance!
Here is the code that i tested
topo = TopExp_Explorer() topo.Init(slab_shape.geometry, TopAbs_FACE) faces = [] while topo.More(): fc = topods_Face(topo.Current()) faces.append(fc) topo.Next() #Extract the faces of the slab shape for face in faces: surf = BRep_Tool_Surface(face) #Get the plane that represent the face plane = OCC.Core.Geom.Handle_Geom_Plane_DownCast(surf).GetObject()
Original comment by thomas on 2021-08-07 12:54:55
When using pythonocc 7.4.0 all GetObject() calls should simply be removed. Also don't use Handle_Geom_Plane, but just Geom_Plane.