mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-05 23:41:44 +00:00
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:
@@ -2440,13 +2440,13 @@ class Drawing(bonsai.core.tool.Drawing):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def is_drawing_active(cls) -> bool:
|
def is_drawing_active(cls) -> bool:
|
||||||
camera = bpy.context.scene.camera
|
camera = bpy.context.scene.camera
|
||||||
area = tool.Blender.get_view3d_area()
|
if not (camera is not None and camera.type == "CAMERA" and tool.Blender.get_ifc_definition_id(camera)):
|
||||||
return bool(
|
return False
|
||||||
camera is not None
|
# A VIEW_3D area is meaningless (and unobtainable) in background
|
||||||
and camera.type == "CAMERA"
|
# mode, but isn't otherwise required to generate a drawing.
|
||||||
and tool.Blender.get_ifc_definition_id(camera)
|
if bpy.app.background:
|
||||||
and area is not None
|
return True
|
||||||
)
|
return tool.Blender.get_view3d_area() is not None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_camera_orthographic(cls) -> bool:
|
def is_camera_orthographic(cls) -> bool:
|
||||||
|
|||||||
@@ -1038,3 +1038,27 @@ class TestAddReferenceImage(NewFile):
|
|||||||
|
|
||||||
uv_node = material_nodes["Texture Coordinate"]
|
uv_node = material_nodes["Texture Coordinate"]
|
||||||
assert len(uv_node.outputs["Generated"].links[:]) == 1
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user