将pythonocc编辑成函数放入窗口程序时时发生闪退

将pythonocc编辑成函数放入窗口程序时时发生闪退

img


```python
#三维模型
def py3d(ui):
    data3 = solve(ui)
    c1 = -data3[2] / 2
    c2 = data3[2] / 2
    c5 = -data3[5] / 2
    c6 = data3[5] / 2
    d7 = data3[3] + data3[4]
    c9 = -data3[0] / 2
    c10 = data3[0] / 2
    d11 = data3[1] + data3[3] + data3[4]

    time.sleep(0.5)
    # 三维模型建立
    E11 = BRepBuilderAPI_MakeEdge(gp_Pnt(c1, 0., 0.), gp_Pnt(c2, 0., 0.)).Edge()
    E12 = BRepBuilderAPI_MakeEdge(gp_Pnt(c2, 0., 0.), gp_Pnt(c2, data3[3], 0.)).Edge()
    E13 = BRepBuilderAPI_MakeEdge(gp_Pnt(c2, data3[3], 0.), gp_Pnt(c6, data3[3], 0.)).Edge()
    E14 = BRepBuilderAPI_MakeEdge(gp_Pnt(c6, data3[3], 0.), gp_Pnt(c6, d7, 0.)).Edge()
    E15 = BRepBuilderAPI_MakeEdge(gp_Pnt(c6, d7, 0.), gp_Pnt(c10, d7, 0.)).Edge()
    E16 = BRepBuilderAPI_MakeEdge(gp_Pnt(c10, d7, 0.), gp_Pnt(c10, d11, 0.)).Edge()
    E17 = BRepBuilderAPI_MakeEdge(gp_Pnt(c10, d11, 0.), gp_Pnt(c9, d11, 0.)).Edge()
    E18 = BRepBuilderAPI_MakeEdge(gp_Pnt(c9, d11, 0.), gp_Pnt(c9, d7, 0.)).Edge()
    E19 = BRepBuilderAPI_MakeEdge(gp_Pnt(c9, d7, 0.), gp_Pnt(c5, d7, 0.)).Edge()
    E110 = BRepBuilderAPI_MakeEdge(gp_Pnt(c5, d7, 0.), gp_Pnt(c5, data3[3], 0.)).Edge()
    E111 = BRepBuilderAPI_MakeEdge(gp_Pnt(c5, data3[3], 0.), gp_Pnt(c1, data3[3], 0.)).Edge()
    E112 = BRepBuilderAPI_MakeEdge(gp_Pnt(c1, data3[3], 0.), gp_Pnt(c1, 0., 0.)).Edge()

    W1 = BRepBuilderAPI_MakeWire(E11, E12, E13, E14)
    W2 = BRepBuilderAPI_MakeWire(E15, E16, E17, E18)
    W3 = BRepBuilderAPI_MakeWire(E19, E110, E111, E112)

    W = BRepBuilderAPI_MakeWire()
    W.Add(W1.Wire())
    W.Add(W2.Wire())
    W.Add(W3.Wire())

    S = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(W.Wire()).Face(), gp_Vec(0., 0, 30000))

    from OCC.Display.SimpleGui import init_display

    display, start_display, add_menu, add_function_to_menu = init_display()
    display.DisplayShape(W.Shape(), update=True)
    display.DisplayShape(S.Shape(), update=True)

    start_display()



主函数如下


```python
if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    ui.pushButton_2.clicked.connect(partial(solve, ui))
    ui.pushButton_3.clicked.connect(partial(clear, ui))
    ui.pushButton_4.clicked.connect(partial(py3d, ui))
    ui.pushButton_5.clicked.connect(partial(pyccad, ui))


    sys.exit(app.exec_())


窗口程序运行时,点击相应按钮,三维模型会呈现出来然后瞬间消失

看看你的3d的环境的配置,显卡的设置。