I am running into an issue with the code below. When the button is hit the code should grab the next model and display it, however, the old mesh is still present in the image and doesn't go away. In VTKPlotLib how do you erase the previous mesh, without destroying the qtfigure and messing up the flow of gui application?
from PyQt5 import QtWidgets
import vtkplotlib as vpl
from PyQt5.QtWidgets import QLineEdit, QMessageBox
from stl.mesh import Mesh
class Tagger(QtWidgets.QWidget):
def __init__(self):
super().__init__()
# Go for a vertical stack layout.
vbox = QtWidgets.QVBoxLayout()
self.setLayout(vbox)
self.setWindowTitle("Tagging Engine")
# Create the figure
self.figure = vpl.QtFigure2()
self.figure.add_preset_views()
# Create a button and attach a callback.
self.button = QtWidgets.QPushButton("Load Next Model")
self.button.released.connect(self.button_pressed_cb)
# Create textbox
self.textbox = QLineEdit(self)
self.textbox.move(20, 20)
self.textbox.resize(280, 40)
# Create a button and attach a callback.
self.button2 = QtWidgets.QPushButton("Save Current Data")
self.button2.released.connect(self.button_pressed_save)
# QtFigures are QWidgets and are added to layouts with `addWidget`
vbox.addWidget(self.button)
vbox.addWidget(self.textbox)
vbox.addWidget(self.button2)
vbox.addWidget(self.figure)
def button_pressed_cb(self):
self.mesh = Mesh.from_file(r"C:/examplefile.stl")
vpl.mesh_plot(mesh_data=self.mesh, color="#94b1ff")
# Reposition the camera to better fit to the model
vpl.reset_camera(self.figure)
self.figure.update()

bwoodsend/vtkplotlibissue 2 does mention:Since
mesh_plotreturns avtkplotlib.mesh_plot, you could memorize it in order to remove it at the next call:fig.remove_plot(mesh)can be used to remove a plot from the figure, provided you have references to both the figure and the plot you want to remove.In your case,
self.figureis the figure andself.mesh_plotis the plot you want to remove.You could also use
fig -= meshas a shorthand forfig.remove_plot(mesh), if you prefer.Additionally, if you want to remove all plots from the figure, you could use
fig -= fig.plots. This would be equivalent to aclear_figurefunction, if one were available.