Menu

Problem with importing modules pythonocc

Help
JP Mertens
2018-11-06
2020-12-03
  • JP Mertens

    JP Mertens - 2018-11-06

    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

     
  • JP Mertens

    JP Mertens - 2018-11-07

    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

     
  • Thomas Krijnen

    Thomas Krijnen - 2018-11-09

    I think there are known issues running the PythonOCC viewer module from PyCharm. Try running from the command line directly.

    Kind regards,
    Thomas

     
  • JP Mertens

    JP Mertens - 2018-12-03

    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)

    wires = OCC.TopTools.TopTools_HSequenceOfShape()
    wires_handle = OCC.TopTools.Handle_TopTools_HSequenceOfShape(wires)
    ###
    

    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

     
  • Thomas Krijnen

    Thomas Krijnen - 2018-12-03

    section_edges = OCC.BRepAlgoAPI.BRepAlgoAPI_Section(section_face, shape).Shape()

    I think that should be section_face and set section_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.

     
  • JP Mertens

    JP Mertens - 2018-12-05

    Hi Thomas,

    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!

     
  • Thomas Krijnen

    Thomas Krijnen - 2018-12-05

    You're still overwriting section_edges with a single edge.

    I meant to replace section_edges = OCC.TopoDS.topods.Edge(exp.Current()) with section_edges.append(OCC.TopoDS.topods.Edge(exp.Current()))

     
  • JP Mertens

    JP Mertens - 2018-12-10

    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)

    section = OCC.BRepAlgoAPI.BRepAlgoAPI_Section(section_face, shape).Shape()
    
    exp = OCC.TopExp.TopExp_Explorer(section, OCC.TopAbs.TopAbs_EDGE)
    section_edges = []
    while exp.More():
        edge = OCC.TopoDS.topods.Edge(exp.Current())
        exp.Next()
        section_edges.append(edge)
    
     
  • Thomas Krijnen

    Thomas Krijnen - 2018-12-10

    Yep, looks good to me. Can you also post that to the academy website? Thanks.

     
  • Hamid Kiavarz

    Hamid Kiavarz - 2020-12-03

    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)

        I need to extract the faces of a wall
    
        Thanks,
        Hamid
    
     

Log in to post a comment.