how to save objects that are in render window in a file and reopen as separate objects later.

Hi. I have developed a program in python using vtk which is used for 3D image processing. In this app user import some stl files or create widgets like contour widget or sphere widget and etc. Now i want to add project save tool so user can save scene as project file and open again later . What is the best solution?

Try vtkPicker. I haven’t used this class before, but it seems like you select your desired object with vtkPicker::Pick, then there are a couple of methods that allow you to get the data for the thing that was picked, such as vtkPicker::GetDataSet.

Thanks for your quick reply. Yes, I can get the actor information via vtkPicker, but I need a tool that automatically saves all the objects inside the render window to one file so they can be imported into the software later as independent objects. Similar to saving the project in other software.
I tried the exporter,

  • The exporter saves all objects in one file, but after importing the saved file, all objects are imported as one object and unlike before saving, they are not independent of each other.
  • The exporter saves all objects as polydata (a contour widget is saved as polydata and some of its properties are not saved like attached poly data or nodes).

You could use vtkAppendPolyDataFilter to add them all together I suppose? Then use vtkXMLPolyDataWriter to save them to a file.

Hello,

I believe the quickest way to save and reload VTK objects is by means of some of the file formats natively supported by VTK. Please, take a look at this: https://vtk.org/Wiki/VTK/Writing_VTK_files_using_python

cheers,

Paulo