How would one set the background image through python?
I can tell PV to use a background image through:
GetActiveView().UseTexturedBackground = 1
But I can’t figure out how to load an image.
repr(GetActiveView().BackgroundTexture)
returns 'None'
and once an image is already loaded through the GUI it can be changed through:
GetActiveView().BackgroundTexture.FileName = 'C:\path\to\image.png'
Trace doesn’t capture the GUI action and saving a python state fails when a background image is loaded.
1 Like
mwestphal
(Mathieu Westphal (Kitware))
2
Not supported directly. You have to create the proxy yourself :
proxy=servermanager.CreateProxy("textures","ImageTexture")
prop=proxy.GetProperty("FileName")
prop.SetElement(0, "path/to/image.png")
proxy.UpdateVTKObjects()
GetActiveView().BackgroundTexture = proxy
Render()
Edit : See the much better solution from @jfavre a few messages down.
Thanks Mathieu, I wasn’t aware of how to create proxy objects by these means.
I’ll keep this in mind for any other actions that aren’t captured by Trace.
cory.quammen
(Cory Quammen (Kitware))
4
jfavre
(Jean M. Favre)
5
I use the following code which seems a bit simpler:
texture = servermanager.rendering.ImageTexture()
texture.FileName = "earth_2048x1024.jpg"
GetActiveView().UseTexturedBackground = 1
GetActiveView().BackgroundTexture = texture
Render()
Indeed that does seem more akin to the general paraview.simple format.
Thanks Jean “Fav-re” (There’s Something About Mary/Brett Favre reference)
mwestphal
(Mathieu Westphal (Kitware))
7
@jfavre : Indeed, I always forgot about this simpler interface. Your solution is the right one.