# Programmatically set background image

**URL:** https://discourse.paraview.org/t/programmatically-set-background-image/2574
**Category:** ParaView Support
**Tags:** python
**Created:** [September 17, 2019, 6:14pm UTC](https://discourse.paraview.org/t/programmatically-set-background-image/2574 "2019-09-17T18:14:53Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![theodorebaltis](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/t/e480ec/32.png) [@theodorebaltis](https://discourse.paraview.org/u/theodorebaltis)
#### Post date: [September 17, 2019, 6:14pm UTC](https://discourse.paraview.org/t/programmatically-set-background-image/2574/1 "2019-09-17T18:14:53Z")

</div>

How would one set the background image through python?

I can tell PV to use a background image through:

```python
GetActiveView().UseTexturedBackground = 1

```

But I can’t figure out how to load an image.

```python
repr(GetActiveView().BackgroundTexture)

```

returns `'None'` and once an image is already loaded through the GUI it can be changed through:

```python
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.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [September 18, 2019, 2:17am UTC](https://discourse.paraview.org/t/programmatically-set-background-image/2574/2 "2019-09-18T02:17:00Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![theodorebaltis](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/t/e480ec/32.png) [@theodorebaltis](https://discourse.paraview.org/u/theodorebaltis)
#### Post date: [September 18, 2019, 2:13pm UTC](https://discourse.paraview.org/t/programmatically-set-background-image/2574/3 "2019-09-18T14:13:33Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [September 18, 2019, 2:16pm UTC](https://discourse.paraview.org/t/programmatically-set-background-image/2574/4 "2019-09-18T14:16:49Z")

</div>

I have opened an issue here: [https://gitlab.kitware.com/paraview/paraview/issues/19335](https://gitlab.kitware.com/paraview/paraview/issues/19335)

---

<div class="post-metadata">

### Author: ![jfavre](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/j/b5ac83/32.png) [@jfavre](https://discourse.paraview.org/u/jfavre)
#### Post date: [September 18, 2019, 2:35pm UTC](https://discourse.paraview.org/t/programmatically-set-background-image/2574/5 "2019-09-18T14:35:05Z")

</div>

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()
```

---

<div class="post-metadata">

### Author: ![theodorebaltis](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/t/e480ec/32.png) [@theodorebaltis](https://discourse.paraview.org/u/theodorebaltis)
#### Post date: [September 18, 2019, 2:41pm UTC](https://discourse.paraview.org/t/programmatically-set-background-image/2574/6 "2019-09-18T14:41:15Z")

</div>

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

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

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [September 19, 2019, 2:18am UTC](https://discourse.paraview.org/t/programmatically-set-background-image/2574/7 "2019-09-19T02:18:39Z")

</div>

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