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
+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