Closed khem1123 closed 2 years ago
Using the from_multi_file method you can load files with multiple meshes like these. After that you can plot those meshes as usual :)
Something along these lines should work:
import numpy
from stl import mesh
from mpl_toolkits import mplot3d
from matplotlib import pyplot
# Create a new plot
figure = pyplot.figure()
axes = mplot3d.Axes3D(figure)
scales = []
# Load the STL files and add the vectors to the plot
for your_mesh in mesh.Mesh.from_multi_file('your_stl_file.stl'):
axes.add_collection3d(mplot3d.art3d.Poly3DCollection(your_mesh.vectors))
scales.append(your_mesh.points.flatten())
# Auto scale to the mesh size
scale = numpy.concatenate(scales)
axes.auto_scale_xyz(scale, scale, scale)
# Show the plot to the screen
pyplot.show()
I tried plotting a stl as described in Doc. " Plotting using matplotlib is equally easy" Apparently, the library read only the first solid even if the .stl file has multiple solids defined for example as solid"A "and" B":
solid A Description of vertices and facets endsolid A solid B Description of vertices and facets endsolid B
Is there a way to read all solids contained in stl file?