1

I created a box in pyvista. When I want to change the size of the box, I will change the bounds values. However, I want to change the size of the box directly by interacting with the box in pyvista display, not in python code. Can I do that in Pyvista?

import pyvista as pv
bounds = [0, 1, 0, 1, 0, 1]
box = pv.Box(bounds)
pl = pv.Plotter()
pl.add_mesh(box)
pl.show()
  • At the time of writing, as far as I know, PyVista does not allow this kind of interaction. Let's hope that one of the PyVista mantainers will reply to this question. – blunova Jul 18 '23 at 12:25

1 Answers1

0

PyVista has widgets that allow for this type of interaction. Slightly modified the example of add_slider_widget [see documentation links at bottom]:

import pyvista as pv
pl = pv.Plotter()

def create_mesh(value):
    bounds = [0, value, 0, value, 0, value]
    box = pv.Box(bounds)
    pl.add_mesh(box, name="box", show_edges=True)

slider = pl.add_slider_widget(
    create_mesh,
    [1, 10],
    title="Box size",
    title_opacity=0.5,
    title_color="red",
    fmt="%0.9f",
    title_height=0.08,
)
pl.show()

enter image description here

https://docs.pyvista.org/version/stable/api/plotting/_autosummary/pyvista.Plotter.add_slider_widget.html

Another example, the custom-callback section of:

https://docs.pyvista.org/version/stable/examples/03-widgets/slider-bar-widget.html#custom-callback

Matthew Flamm
  • 448
  • 3
  • 13