Allow drawing generation in background mode

is_drawing_active() required an open VIEW_3D area purely as a poll()
gate for bim.create_drawing, even though SVG generation is
ifcopenshell.geom-based with no viewport dependency; skip that check
when bpy.app.background is true, since a viewport is neither
obtainable nor meaningful there. Interactive behaviour is unchanged.

Generated with the assistance of an AI coding tool.
This commit is contained in:
Bruno Postle
2026-07-04 09:34:05 +01:00
parent 5db955d40c
commit eafa158ca0
2 changed files with 31 additions and 7 deletions
+7 -7
View File
@@ -2440,13 +2440,13 @@ class Drawing(bonsai.core.tool.Drawing):
@classmethod
def is_drawing_active(cls) -> bool:
camera = bpy.context.scene.camera
area = tool.Blender.get_view3d_area()
return bool(
camera is not None
and camera.type == "CAMERA"
and tool.Blender.get_ifc_definition_id(camera)
and area is not None
)
if not (camera is not None and camera.type == "CAMERA" and tool.Blender.get_ifc_definition_id(camera)):
return False
# A VIEW_3D area is meaningless (and unobtainable) in background
# mode, but isn't otherwise required to generate a drawing.
if bpy.app.background:
return True
return tool.Blender.get_view3d_area() is not None
@classmethod
def is_camera_orthographic(cls) -> bool:
+24
View File
@@ -1038,3 +1038,27 @@ class TestAddReferenceImage(NewFile):
uv_node = material_nodes["Texture Coordinate"]
assert len(uv_node.outputs["Generated"].links[:]) == 1
class TestIsDrawingActive(NewFile):
def test_no_active_camera(self):
bpy.context.scene.camera = None
assert subject.is_drawing_active() is False
def test_active_camera_without_ifc_definition(self):
bpy.context.scene.camera = subject.create_camera("Camera", mathutils.Matrix(), "PERSPECTIVE", "PLAN_VIEW")
assert subject.is_drawing_active() is False
def test_ifc_linked_camera_in_background_mode(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
camera_obj = subject.create_camera("Camera", mathutils.Matrix(), "PERSPECTIVE", "PLAN_VIEW")
drawing = ifc.createIfcAnnotation(ObjectType="DRAWING")
tool.Ifc.link(drawing, camera_obj)
bpy.context.scene.camera = camera_obj
# The test suite itself runs Blender in background mode, where no
# VIEW_3D area can ever exist -- this is exactly the case the fix
# addresses, so this assertion documents that assumption.
assert bpy.app.background is True
assert subject.is_drawing_active() is True