<html><head></head><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> I'm trying to use VTK in python to edit a `.stl` file using the `vtkBoxWidget`. I'm reading the `.stl` file, editing it with the `vtkBoxWidget` by using the mouse/drag in the window interactor and in the end I want to write the new data to a new `.stl` when hitting a certain key.</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""><br id="yiv4972384349yui_3_16_0_1_1457783107108_3262" class=""></div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class="">Here's the code I've been working on:</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""><br id="yiv4972384349yui_3_16_0_1_1457783107108_3266" class=""></div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> #!/usr/bin/env python</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> </div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> import vtk</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> import sys</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> import os</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> </div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> filename = "file.stl"</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> # render the data</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> reader = vtk.vtkSTLReader()</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> reader.SetFileName(filename)</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> </div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> stlMapper = vtk.vtkPolyDataMapper()</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> stlMapper.SetInputConnection(reader.GetOutputPort())</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> </div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> # create an actor for our scene</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> </div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> stlActor = vtk.vtkActor()</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> stlActor.SetMapper(stlMapper)</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> </div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> </div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> </div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> ren = vtk.vtkRenderer()</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> renWin = vtk.vtkRenderWindow()</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> renWin.AddRenderer(ren)</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> iren = vtk.vtkRenderWindowInteractor()</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> iren.SetRenderWindow(renWin)</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> </div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> # The box widget observes the events invoked by the render window</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> # interactor. These events come from user interaction in the render</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> # window.</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> boxWidget = vtk.vtkBoxWidget()</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> boxWidget.SetInteractor(iren)</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> boxWidget.SetPlaceFactor(1.25)</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> </div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> # Add the actors to the renderer, set the background and window size.</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> ren.AddActor(stlActor)</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> ren.SetBackground(0.1, 0.2, 0.4)</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> renWin.SetSize(300, 300)</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> </div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> # As the box widget is interacted with, it produces a transformation</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> # matrix that is set on the actor.</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> t = vtk.vtkTransform()</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> def TransformActor(obj, event):</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> global t, stlActor</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> obj.GetTransform(t)</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> stlActor.SetUserTransform(t)</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> </div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> def onKeyPressEvent(self, renderer):</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> key = self.GetKeyCode()</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> if(key=='l'):</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> print stlActor.GetBounds()</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> if(os.path.isfile("done.stl")==1):</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> os.remove("done.stl")</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> print stlActor.GetMapper().GetInput().GetBounds()</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> stlPolyData = stlActor.GetMapper().GetInput()</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> writer = vtk.vtkSTLWriter()</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> writer.SetFileName("done.stl")</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> writer.AddInputDataObject(stlPolyData)</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> writer.Write()</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> # Place the interactor initially. The actor is used to place and scale</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> # the interactor. An observer is added to the box widget to watch for</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> # interaction events. This event is captured and used to set the</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> # transformation matrix of the actor.</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> boxWidget.SetProp3D(stlActor)</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> boxWidget.PlaceWidget()</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> boxWidget.AddObserver("InteractionEvent", TransformActor)</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> iren.AddObserver('KeyPressEvent', onKeyPressEvent)</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> </div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> iren.Initialize()</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> renWin.Render()</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> iren.Start()</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""><br id="yiv4972384349yui_3_16_0_1_1457783107108_3340" class=""></div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class="">The problem is that I have no idea how to update the `vtkPolyData` or pass the transformations I applied to `vtkActor` to the `vtkPolyData`. In the code above, I tested this with the .GetBounds() in the two print functions. Originally the object had Bounds:</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""><br id="yiv4972384349yui_3_16_0_1_1457783107108_3344" class=""></div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> (-2.0, 2.0, 0.0, 1.625, -1.5, 1.8125)</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""><br id="yiv4972384349yui_3_16_0_1_1457783107108_3348" class=""></div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class="">After updating, the actor Bounds changed, but I can't pass all those properties to the vtkPolyData.</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""><br id="yiv4972384349yui_3_16_0_1_1457783107108_3352" class=""></div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> (-2.1331110248939638, 2.246371570191821, -1.5743578447908013, 2.5817210301577385, -2.1311284932847796, 2.0695034726591715)</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""> (-2.0, 2.0, 0.0, 1.625, -1.5, 1.8125)</div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""><br id="yiv4972384349yui_3_16_0_1_1457783107108_3357" class=""></div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class=""><br id="yiv4972384349yui_3_16_0_1_1457783107108_3360" class=""></div><div id="yiv4972384349yui_3_16_0_1_1457783107108_3220" class="" dir="ltr">Thanks!</div></div></body></html>