Reset active drawing id if we removed the active drawing

Previously there was an error if you remove all drawings:
```
Traceback (most recent call last):
  File "\addons\blenderbim\bim\module\drawing\ui.py", line 182, in draw
    DrawingsData.load()
  File "\addons\blenderbim\bim\module\drawing\data.py", line 106, in load
    "active_drawing_pset_data": cls.active_drawing_pset_data(),
  File "\addons\blenderbim\bim\module\drawing\data.py", line 134, in active_drawing_pset_data
    drawing = ifc_file.by_id(bpy.context.scene.DocProperties.active_drawing_id)
  File "\addons\blenderbim\libs\site\packages\ifcopenshell\file.py", line 326, in by_id
    return self[id]
  File "\addons\blenderbim\libs\site\packages\ifcopenshell\file.py", line 314, in __getitem__
    return entity_instance(self.wrapped_data.by_id(key), self)
  File "\addons\blenderbim\libs\site\packages\ifcopenshell\ifcopenshell_wrapper.py", line 4517, in by_id
    return _ifcopenshell_wrapper.file_by_id(self, id)
RuntimeError: Instance #1 077 not found
```
This commit is contained in:
Andrej730
2023-05-19 15:40:58 +05:00
parent af2e0b07c3
commit 3601a1d43b
@@ -1410,10 +1410,14 @@ class RemoveDrawing(bpy.types.Operator, Operator):
drawings = [tool.Ifc.get().by_id(self.drawing)]
print("Removing drawings: {}".format([d for d in drawings]))
removed_drawings = [drawing.id() for drawing in drawings]
for drawing in drawings:
core.remove_drawing(tool.Ifc, tool.Drawing, drawing=drawing)
active_drawing_id = context.scene.DocProperties.active_drawing_id
if active_drawing_id in removed_drawings:
context.scene.DocProperties.active_drawing_id = 0
class ReloadDrawingStyles(bpy.types.Operator):
bl_idname = "bim.reload_drawing_styles"