diff --git a/src/bonsai/bonsai/bim/module/drawing/operator.py b/src/bonsai/bonsai/bim/module/drawing/operator.py index d596d0fd9c..1320145620 100644 --- a/src/bonsai/bonsai/bim/module/drawing/operator.py +++ b/src/bonsai/bonsai/bim/module/drawing/operator.py @@ -1726,7 +1726,9 @@ class OpenLayout(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): self.props = tool.Drawing.get_document_props() - sheet = tool.Ifc.get().by_id(self.props.sheets[self.props.active_sheet_index].ifc_definition_id) + sheet_item = tool.Drawing.get_active_sheet_item() + assert sheet_item + sheet = tool.Ifc.get().by_id(sheet_item.ifc_definition_id) sheet_builder = sheeter.SheetBuilder() sheet_builder.update_sheet_drawing_sizes(sheet) core.open_layout(tool.Drawing, sheet=sheet) @@ -1790,7 +1792,9 @@ class OpenSheet(bpy.types.Operator): tool.Ifc.get().by_id(s.ifc_definition_id) for s in self.props.sheets if s.is_sheet and s.is_selected ] else: - sheets = [tool.Ifc.get().by_id(self.props.sheets[self.props.active_sheet_index].ifc_definition_id)] + sheet_item = tool.Drawing.get_active_sheet_item() + assert sheet_item + sheets = [tool.Ifc.get().by_id(sheet_item.ifc_definition_id)] sheet_uris: list[str] = [] sheets_not_found: list[str] = [] @@ -1855,7 +1859,7 @@ class AddDrawingToSheet(bpy.types.Operator, tool.Ifc.Operator): assert active_drawing ifc_file = tool.Ifc.get() - active_sheet = tool.Drawing.get_active_sheet(context) + active_sheet = tool.Drawing.get_active_sheet() drawing = tool.Ifc.get().by_id(active_drawing.ifc_definition_id) drawing_reference = tool.Drawing.get_drawing_document(drawing) @@ -1969,7 +1973,9 @@ class CreateSheets(bpy.types.Operator, tool.Ifc.Operator): if self.create_all: sheets = [tool.Ifc.get().by_id(s.ifc_definition_id) for s in props.sheets if s.is_sheet and s.is_selected] else: - sheets = [tool.Ifc.get().by_id(props.sheets[props.active_sheet_index].ifc_definition_id)] + sheet_item = tool.Drawing.get_active_sheet_item() + assert sheet_item + sheets = [tool.Ifc.get().by_id(sheet_item.ifc_definition_id)] warnings: list[tool.Drawing.SheetWarningType] = [] n_sheets_created = 0 @@ -2735,7 +2741,7 @@ class AddScheduleToSheet(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): props = tool.Drawing.get_document_props() active_schedule = props.schedules[props.active_schedule_index] - active_sheet = tool.Drawing.get_active_sheet(context) + active_sheet = tool.Drawing.get_active_sheet() ifc_file = tool.Ifc.get() schedule = tool.Ifc.get().by_id(active_schedule.ifc_definition_id) if tool.Ifc.get_schema() == "IFC2X3": @@ -2803,7 +2809,7 @@ class AddReferenceToSheet(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): props = tool.Drawing.get_document_props() active_reference = props.references[props.active_reference_index] - active_sheet = tool.Drawing.get_active_sheet(context) + active_sheet = tool.Drawing.get_active_sheet() ifc_file = tool.Ifc.get() extref = tool.Ifc.get().by_id(active_reference.ifc_definition_id) if tool.Ifc.get_schema() == "IFC2X3": @@ -3219,8 +3225,9 @@ class EditSheet(bpy.types.Operator, tool.Ifc.Operator): def invoke(self, context, event): assert context.window_manager - self.props = tool.Drawing.get_document_props() - sheet = tool.Ifc.get().by_id(self.props.sheets[self.props.active_sheet_index].ifc_definition_id) + sheet_item = tool.Drawing.get_active_sheet_item() + assert sheet_item + sheet = tool.Ifc.get().by_id(sheet_item.ifc_definition_id) if sheet.is_a("IfcDocumentInformation"): self.document_type = "SHEET" self.name = sheet.Name @@ -3248,15 +3255,17 @@ class EditSheet(bpy.types.Operator, tool.Ifc.Operator): row.prop(self, "identification", text="Identification") def _execute(self, context): - self.props = tool.Drawing.get_document_props() + props = tool.Drawing.get_document_props() ifc_file = tool.Ifc.get() - sheet = tool.Ifc.get().by_id(self.props.sheets[self.props.active_sheet_index].ifc_definition_id) + sheet_item = tool.Drawing.get_active_sheet_item() + assert sheet_item + sheet = tool.Ifc.get().by_id(sheet_item.ifc_definition_id) if self.document_type == "SHEET": core.rename_sheet(tool.Ifc, tool.Drawing, sheet=sheet, identification=self.identification, name=self.name) elif self.document_type == "EMBEDDED": core.rename_reference(tool.Ifc, tool.Drawing, reference=sheet, identification=self.identification) elif self.document_type == "TITLEBLOCK": - titleblock = self.props.titleblock + titleblock = props.titleblock reference = sheet sheet = tool.Drawing.get_reference_document(reference) assert sheet diff --git a/src/bonsai/bonsai/bim/module/drawing/ui.py b/src/bonsai/bonsai/bim/module/drawing/ui.py index 2de1d2991c..675684f6c7 100644 --- a/src/bonsai/bonsai/bim/module/drawing/ui.py +++ b/src/bonsai/bonsai/bim/module/drawing/ui.py @@ -419,6 +419,7 @@ class BIM_PT_sheets(Panel): draw_project_not_saved_ui(self) return + assert self.layout self.props = tool.Drawing.get_document_props() if not self.props.is_editing_sheets: @@ -432,8 +433,8 @@ class BIM_PT_sheets(Panel): row.operator("bim.add_sheet", text="", icon="ADD") row.operator("bim.disable_editing_sheets", text="", icon="CANCEL") - if self.props.sheets and self.props.active_sheet_index < len(self.props.sheets): - active_sheet = self.props.sheets[self.props.active_sheet_index] + active_sheet = tool.Drawing.get_active_sheet_item() + if active_sheet: row = self.layout.row(align=True) row2 = row.row(align=True) if active_sheet.is_sheet: diff --git a/src/bonsai/bonsai/tool/drawing.py b/src/bonsai/bonsai/tool/drawing.py index 2846600239..4b2fb45661 100644 --- a/src/bonsai/bonsai/tool/drawing.py +++ b/src/bonsai/bonsai/tool/drawing.py @@ -1037,8 +1037,9 @@ class Drawing(bonsai.core.tool.Drawing): new.reference_type = reference_description @classmethod - def get_active_sheet(cls, context: bpy.types.Context) -> Sheet: + def get_active_sheet(cls) -> Sheet: props = cls.get_document_props() + # Will also get active sheet even if one of it's subitems selected (drawings, etc). return next(s for s in props.sheets[: props.active_sheet_index + 1][::-1] if s.is_sheet) @classmethod