I am running blender as a background process via a script made in python.
What I want to achieve here to transform the UVs via the same script.
I am able to transform the UVs in the text editor in blender but when I run the code via a script it gives me an error and the line on which the error is - bpy.context.area.ui_type = ‘UV’
The thing here is that the context.area show none when the code executed via script.
Hi @Shubham-Tyagi-LF
" This is a dedicated place for Blender module teams to reach out to contributors - development questions are welcome.
For feature requests, please use rightclickselect.com. For questions about how to use Blender, ask on one of the community forums."
You will have to switch context. Because not all operators are available within every context, due to the poll method, that is supposed to makes things a little bit more safe and organized. But anyway you can bypass this restriction.
This is an except from one of my scripts but it shows the technique used. If I remember correctly this code works, only if Image Editor panel is available in front of the user. So it means that the code will work best only with a template .blend file loaded (with proper UI setup) and the script then run from command line.
# access image editor context to save it
# (ALTERNATIVE - BUT CONTEXT CONSTRAINED)
done = False
for area in context.screen.areas:
if area.type == 'IMAGE_EDITOR':
ctx = bpy.context.copy()
ctx['area'] = area
ctx['region'] = [x for x in area.regions if x.type == 'WINDOW'][0]
bpy.ops.image.save_as(ctx, save_as_render=True, copy=True, filepath="//untitled.png", relative_path=True, show_multiview=False, use_multiview=False)
done = True