Hello,
I want do display an stl file in plotly dash. Can anybody help me? I want to use the library dash_vtk.
Regards,
Suzan.
Hello,
I want do display an stl file in plotly dash. Can anybody help me? I want to use the library dash_vtk.
Regards,
Suzan.
Hi @sfritzke welcome to the community.
I used meshio to convert the *.stl
into *.vtk
.
This is the quick and dirty app:
import dash
from dash import html
import vtk
import dash_vtk
from dash_vtk.utils import to_mesh_state
# set type of reader to be used. The meshio created vtk file requires the UnstructuredGridReader
reader = vtk.vtkUnstructuredGridReader()
# reade the file
reader.SetFileName('your_vtk_file.vtk')
reader.Update()
dataset = reader.GetOutput()
# Use helper to get a mesh structure that can be passed as-is to a Mesh
mesh_state = to_mesh_state(dataset)
content = dash_vtk.View(
background=[0.0, 0.0, 0.0],
triggerRender=1.,
children=[
dash_vtk.GeometryRepresentation(
showCubeAxes=True,
# cubeAxesStyle={
# "height": 2000,
# "startingHeight": 10,
# "width": 2000,
# },
property={
"edgeVisibility": False,
#"VertexVisibility": True,
"EdgeColor": [0.0, 0.0, 0.0],
#"VertexColor": [1.0, 1.0, 1.0],
"Color": [0.6, 0.0, 1.0],
"Opacity": 1.0,
},
children=[
dash_vtk.Mesh(state=mesh_state)
]
)
]
)
# initiate app
app = dash.Dash(__name__)
app.layout = html.Div(
children=[content],
)
if __name__ == "__main__":
app.run(debug=True)