ObjExporter issue

I’m trying to export model in .OBJ file …
debug window error: obj files only support on renderer per window.

Code:

o = vtk.vtkOBJExporter()
o.SetFilePrefix(’/tmp/obj/fibers’)
lm = slicer.app.layoutManager()
tdv = lm.threeDWidget(0).threeDView()
rw = tdv.renderWindow()
o.SetRenderWindow(rw)
o.Write()

whats wrong in this code… please help

Thanks,

There is an (unnecessary) limitation in the vtkOBJExporter that causes the issue. I’ve submitted a pull request with the fix (coincidentally, I’ve just worked on OBJ exporter problems and included this fix as well): https://gitlab.kitware.com/vtk/vtk/merge_requests/4084

Until the fix is integrated, you can use a workaround of moving the renderer to another render window. This allows the export to complete successfully and then the application crashes (if the goal is to just export to OBJ then the crash should not be an issue).

lm = slicer.app.layoutManager()
tdv = lm.threeDWidget(0).threeDView()
rw = tdv.renderWindow()
# Move renderer temporarily into another renderWindow
# It will make the application crash, but it allows the scene export to complete successfully.
rw2 = vtk.vtkRenderWindow()
rw2.AddRenderer(rw.GetRenderers().GetFirstRenderer())
o = vtk.vtkOBJExporter()
o.SetFilePrefix('c:/tmp/test')
o.SetRenderWindow(rw2)
o.Write()
3 Likes

Thank you so much, it works like a charm …Finally got the obj output.
please update once this issue gets resolved or any other non crashing solution you get,

thanks,