I use this command for running (open) Blender
blender --factory-startup --python path_to_script script.py
In script.py
i tried to call
bpy.ops.view3d.view_all(center=False)
But its get wrong context
So I tried common way to override the context using:
import bpy
def get_view3d():
if bpy.context.area.type != 'VIEW_3D':
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
return area
area = get_view3d()
region = next(region for region in area.regions if region.type == "WINDOW")
with bpy.context.temp_override(area=area, region=region):
# ops that need 3Dview context should put here
bpy.ops.view3d.view_all(center=False)
The problem is it's return None
when executing bpy.context.area
How to get 3D viewport context using script when running Blender using Command Line (Windows)?,
The goal is I can use another bpy.ops
that needs a specific active context.