首页 > 解决方案 > 如何在情节中显示OCC

问题描述

我正在尝试在 python 中使用 OCC 显示一个 stp 文件。有用。也就是说,我可以使用 pythonocc 在我的本地机器上显示它。现在,我正在尝试使用 plotly 以破折号显示它。我试图在破折号中显示 occ 图像,而不是在我的本地机器中。

代码是:

# -*- coding: utf-8 -*-

# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
import dash_core_components as dcc

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)


import sys
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
import pandas as pd

from OCC.Core.STEPControl import STEPControl_Reader
from OCC.Core.IFSelect import IFSelect_RetDone, IFSelect_ItemsByEntity
from OCC.Display.SimpleGui import init_display
from OCC.Core.ShapeExtend import ShapeExtend_CompositeSurface
from OCC.Core.GProp import GProp_GProps
from OCC.Core.BRepGProp import brepgprop_VolumeProperties
from OCC.Extend.DataExchange import read_step_file

input_file  = 'test.stp'   # input STEP (AP203/AP214 file)
prop = GProp_GProps()
extend = ShapeExtend_CompositeSurface()
step_reader = STEPControl_Reader()
status = step_reader.ReadFile(input_file)

if status == IFSelect_RetDone:  # check status
    failsonly = False
    step_reader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity)
    step_reader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity)

    ok = step_reader.TransferRoot(1)
    _nbs = step_reader.NbShapes()
    aResShape = step_reader.Shape(1)

else:
    print("Error: can't read file.")
    sys.exit(0)
print(aResShape)
display, start_display, add_menu, add_function_to_menu = init_display()

'''display, start_display, add_menu, add_function_to_menu = init_display()
display.DisplayShape(aResShape, update=True)
start_display()'''

app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    html.Div(children='''
        Dash: A web application framework for Python.
    '''),
    
          display.DisplayShape(aResShape, update=True)
])

if __name__ == '__main__':
    app.run_server(debug=True)

但是,它不起作用。

我只是一个新手,所以有人可以帮忙吗?

标签: pythonplotly-dashpythonocc

解决方案


推荐阅读