Traceback (most recent call last):
File "C:/Users/Jan Philipp Mertens/PycharmProjects/untitled/Cross section.py", line 4, in <module>
import OCC.Utils
ImportError: No module named 'OCC.Utils'</module>
was it maybe renamed?
Thanks in advance
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Are you by any chance referring to the code you found in this article [1]? I made a comment [2] there as well about the changes in newer PythonOCC versions. The article is from 2015 and has not since been updated. I think that particular OCC.Utils.Topo can now be found here [3]. Overall the required changes should be minimal. If you get things working, it would be very much appreciated if you leave some instructions there in a comment for future users.
Thank you for the quick responce. Indeed your workaround from [2] helped it not crashing anymore. However the viewer now freezes up without crashing when I run the programm. I tried the ideas from Wouter Coebergh but I can't seem to import topods.
I will leave a comment once I get it working.
Best,
JP
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
as a workaround for section_edges = list(OCC.Utils.Topo(section).edges())
However it says object of type TopoDS_Edge has no length. Any idea what I am doing wrong here? Thanks again in advance
Best regards
JP
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for your quick reply and sorry for continuing to ask, since I am very new to this.
I now have:
for product, shape in product_shapes:
section = OCC.BRepAlgoAPI.BRepAlgoAPI_Section(section_face, shape).Shape()
section_edges = []
exp = OCC.TopExp.TopExp_Explorer(section, OCC.TopAbs.TopAbs_EDGE)
while exp.More():
section_edges = OCC.TopoDS.topods.Edge(exp.Current())
exp.Next()
section_edges.append(OCC.TopoDS.topods.Edge(exp.Current()))
if len(section_edges) > 0:
edges = OCC.TopTools.TopTools_HSequenceOfShape()
edges_handle = OCC.TopTools.Handle_TopTools_HSequenceOfShape(edges)
wires = OCC.TopTools.TopTools_HSequenceOfShape()
wires_handle = OCC.TopTools.Handle_TopTools_HSequenceOfShape(wires)
however i get: section_edges.append(OCC.TopoDS.topods.Edge(exp.Current()))
AttributeError: 'TopoDS_Edge' object has no attribute 'append'
Did I insert the line at the right place, or is it supposed to go in the while loop? I get the same exception when I incert in the loop aswell. section_edges.append(OCC.TopoDS.topods.Edge(exp.Current()))
Thanks again!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi I can't imort Utils from OCC
Traceback (most recent call last):
File "C:/Users/Jan Philipp Mertens/PycharmProjects/untitled/Cross section.py", line 4, in <module>
import OCC.Utils
ImportError: No module named 'OCC.Utils'</module>
was it maybe renamed?
Thanks in advance
Hi,
Are you by any chance referring to the code you found in this article [1]? I made a comment [2] there as well about the changes in newer PythonOCC versions. The article is from 2015 and has not since been updated. I think that particular
OCC.Utils.Topo
can now be found here [3]. Overall the required changes should be minimal. If you get things working, it would be very much appreciated if you leave some instructions there in a comment for future users.Kind regards,
Thomas
[1] http://academy.ifcopenshell.org/using-ifcopenshell-and-pythonocc-to-generate-cross-sections-directly-from-an-ifc-file/
[2] http://academy.ifcopenshell.org/using-ifcopenshell-and-pythonocc-to-generate-cross-sections-directly-from-an-ifc-file/#comment-57
[3] https://github.com/tpaviot/pythonocc-core/blob/master/src/Extend/TopologyUtils.py
Hi Thomas,
Thank you for the quick responce. Indeed your workaround from [2] helped it not crashing anymore. However the viewer now freezes up without crashing when I run the programm. I tried the ideas from Wouter Coebergh but I can't seem to import topods.
I will leave a comment once I get it working.
Best,
JP
I think there are known issues running the PythonOCC viewer module from PyCharm. Try running from the command line directly.
Kind regards,
Thomas
Hi Thomas,
I came back to work on it again.
I wrote this
for product, shape in product_shapes:
section_edges = OCC.BRepAlgoAPI.BRepAlgoAPI_Section(section_face, shape).Shape()
exp = OCC.TopExp.TopExp_Explorer(section_face, OCC.TopAbs.TopAbs_EDGE)
while exp.More():
section_edges = OCC.TopoDS.topods.Edge(exp.Current())
exp.Next()
if len(section_edges) > 0:
edges = OCC.TopTools.TopTools_HSequenceOfShape()
edges_handle = OCC.TopTools.Handle_TopTools_HSequenceOfShape(edges)
as a workaround for section_edges = list(OCC.Utils.Topo(section).edges())
However it says object of type TopoDS_Edge has no length. Any idea what I am doing wrong here? Thanks again in advance
Best regards
JP
I think that should be
section_face
and setsection_edges = []
to an empty list.Then you can do
section_edges.append(OCC.TopoDS.topods.Edge(exp.Current()))
, because now you're overwriting the edge.I think then it would work.
Hi Thomas,
Thank you for your quick reply and sorry for continuing to ask, since I am very new to this.
I now have:
however i get: section_edges.append(OCC.TopoDS.topods.Edge(exp.Current()))
AttributeError: 'TopoDS_Edge' object has no attribute 'append'
Did I insert the line at the right place, or is it supposed to go in the while loop? I get the same exception when I incert in the loop aswell.
section_edges.append(OCC.TopoDS.topods.Edge(exp.Current()))
Thanks again!
You're still overwriting
section_edges
with a single edge.I meant to replace
section_edges = OCC.TopoDS.topods.Edge(exp.Current())
withsection_edges.append(OCC.TopoDS.topods.Edge(exp.Current()))
Hi Thomas,
Thanks for the help. In the end after some other changes I got it working with:
for product, shape in product_shapes:
print(product)
Yep, looks good to me. Can you also post that to the academy website? Thanks.
Hi,
What is the equal syntax for the below statements:
topo = OCC.Utils.Topo(shape)
for face in topo.faces():
surf = OCC.BRep.BRep_Tool.Surface(face)