Syntheyes Call Request - background_image_add How to call?

Russ over at Syntheyes asked on Twitter for this:

how do I call background_image_add on the SpaceView3D of my choice from any #python code–console or textedit? (tags fixed)

If you contact him on twitter please let me know, or you can just answer here and I’ll get it to him.
By they way, there is a new script to export tracking information to Blender 2.57 for Syntheyes users.


I took a swing at it but didn’t figure it out completely. Basically got as far as selecting and turning the background image but not how to add a new file. I’ll take another look later but maybe this hacky code will help some.

import bpy
scrn = bpy.context.screen
for a in scrn.areas:
    if a.type == 'VIEW_3D':
        Av3d = a
for s in Av3d.spaces:
    if s.type == 'VIEW_3D':
        Sv3d = s
bimg =['tesla.jpg']
Sv3d.show_background_images = True

###---THIS PART DOESN'T WORK -readonly
#Sv3d.background_images = bimg
###   have to figure out another way to get an image
###   into the background_images datablock.
###   tried bpy.ops.view3d.background_image_add() but
###   I never understand context enough to use the ops module.

Thanks, I’ll pass it on to Russ.
Let me know if you get further.
Much appreciated.