1
$\begingroup$

I'm trying to figure out how to change the Alpha (image opacity) for a background image in the Camera settings "Background Images", but can't quite figure it out, any ideas?

The tooltip says CameraBackgroundImage.alpha and bpy.data.cameras['Camera name'] ... alpha

enter image description here

Q: How to change alpha for background image (camera) with python?

$\endgroup$

1 Answer 1

4
$\begingroup$

Python console

Given the tooltip, and the property being in 'DATA' panel can see that the property belongs to the data part of the camera.

I find autocomplete in the console handy for working these things out.

The data part of the scene camera (it's also the active object C.object. In console C is a shortcut for bpy.context (see startup message).

>>> C.scene.camera
bpy.data.objects['Camera']

>>> cam = C.scene.camera.data
>>> cam
bpy.data.cameras['Camera']

Ok, if you autocomplete on cam.<TAB> will notice that it has a background_images property... Ok it's a collection

Here I've looped over the collection and displayed the alpha and its attached image.

>>> for img in cam.background_images:
...     img.alpha, img.image
...     
(0.5, bpy.data.images['1b.jpg'])

Set first in list to alpha 1

>>> cam.background_images[0].alpha = 1
$\endgroup$
1
  • $\begingroup$ Yes! Thank you for the clear answer, it works very well. How do I iterate over all and set them all to alpha 1? I can set them by cam.data.background_images[0].alpha = 1 cam.data.background_images[1].alpha = 1 cam.data.background_images[2].alpha = 1 cam.data.background_images[3].alpha = 1 But I'm sure there is a more efficient way of doing it. I tried a few different things, but they didn't work. This is one of the things I tried, but bi has no attribute of alpha. ``` bi = cam.data.background_images for x in bi: bi.alpha = 1 ``` $\endgroup$ Dec 6, 2020 at 5:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .