project camera image onto mesh in background mode - python

I am simply looking for a way to do this with python bindings but the constraint is that I must do this in background. I can do it with python, simply following the steps mentioned in the answer here but it necessarily needs to spawn the GUI window for it to work. Is there a way around it that allows me the same functionality but without the need for a GUI.

Hello,

Why you don’t need it to run in background in the first place ? Maybe there is a workaround for that ?

The other solution would be to recreate similar functionality in a different way. But it seems more involved.
Maybe with UV-Project modifier + bake it’s possible , but it’s more complicated to do and probably slower.

Does blender say something on the terminal while running code on the background ?

Thanks for your response. Unfortunately, having it running in background mode is a hard constraint that I can’t do away with.
When I run my current bpy.ops.paint.project_image() based script with --background, it simply crashes with a segfault and writes a crash log (which doesn’t help much but I’m still attaching here for reference)

# Blender 3.1.2, Commit date: 2022-03-31 17:40, Hash cc66d1020c3b

# backtrace
blender(BLI_system_backtrace+0x20) [0xb340860]
blender() [0x113106d]
/lib/x86_64-linux-gnu/libc.so.6(+0x430c0) [0x7f5c408450c0]
blender(BKE_undosys_step_push_init_with_type+0x1c) [0x231047c]
blender(ED_image_undo_push_begin+0x28) [0x2177f68]
blender() [0x1fa29d6]
blender() [0x1572128]
blender(WM_operator_call_py+0x68) [0x1572d88]
blender() [0x1a56e68]
blender() [0x9eca874]
blender(_PyObject_MakeTpCall+0x88) [0x9e84cd8]
blender(_PyEval_EvalFrameDefault+0xa3db) [0x112d5bb]
blender() [0x9f43364]
blender(_PyObject_FastCallDictTstate+0xca) [0x9e84eba]
blender(_PyObject_Call_Prepend+0xe4) [0x9e85104]
blender() [0x9eeef69]
blender(_PyObject_MakeTpCall+0x88) [0x9e84cd8]
blender(_PyEval_EvalFrameDefault+0xa26e) [0x112d44e]
blender() [0x9f43364]
blender(_PyEval_EvalFrameDefault+0x6f06) [0x112a0e6]
blender(PyEval_EvalCode+0xbc) [0x9f431ec]
blender() [0x9f82104]
blender(PyRun_FileExFlags+0x90) [0x9f839f0]
blender() [0x1a3de07]
blender() [0x112f2ea]
blender(BLI_args_parse+0xc7) [0xb26e407]
blender(main+0x2cb) [0x101c46b]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0x7f5c408260b3]
blender() [0x112d97c]

# Python backtrace
  File "/home/gauravkumar/Downloads/blender/3.1/scripts/modules/bpy/ops.py", line 129 in __call__
  File "/home/gauravkumar/add_texture_blender.py", line 66 in add_texture
  File "/home/gauravkumar/add_texture_blender.py", line 11 in <module>

I’m now looking into UV-project modifier approach. Thanks for the pointer.

Arf ok !
You can try an older version of blender to see if that was always the case.
It should not crash so you may try to report a bug.
But as it’s a quite unusual use of that feature I’m not sure it will be fixed quickly.

Good luck !