Programmatically set background image

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.


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

Not supported directly. You have to create the proxy yourself :

prop.SetElement(0, "path/to/image.png")
GetActiveView().BackgroundTexture = proxy

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.

I have opened an issue here:

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

Indeed that does seem more akin to the general paraview.simple format.

Thanks Jean “Fav-re” (There’s Something About Mary/Brett Favre reference)

@jfavre : Indeed, I always forgot about this simpler interface. Your solution is the right one.