From 17f01bb88c61c08d324b8342431df2f4528c8d69 Mon Sep 17 00:00:00 2001 From: Roy-043 <70520633+Roy-043@users.noreply.github.com> Date: Sat, 27 Sep 2025 02:54:31 +0200 Subject: [PATCH] BIM: fix linked document of BIM_Library task panel (#24169) * BIM: fix linked document of BIM_Library task panel Fixes #22437. The task panel of the BIM_Library command would be linked to the active document, which would to be the temporary Viewer document if that option was checked. Closing that document in the `Insert` function would therefore also close the task panel resulting in errors for following code. Additionally: The code to close the temporary Viewer document was moved to the `Reject` function. Otherwise that document would stay open if the task panel was closed without inserting. --- src/Mod/BIM/bimcommands/BimLibrary.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Mod/BIM/bimcommands/BimLibrary.py b/src/Mod/BIM/bimcommands/BimLibrary.py index 1c75fba37d..8ab9df20f8 100644 --- a/src/Mod/BIM/bimcommands/BimLibrary.py +++ b/src/Mod/BIM/bimcommands/BimLibrary.py @@ -105,8 +105,9 @@ class BIM_Library: # save file paths with forward slashes even on windows pr.SetString("destination", addondir.replace("\\", "/")) libok = True - task = FreeCADGui.Control.showDialog(BIM_Library_TaskPanel(offlinemode=libok)) - task.setDocumentName(FreeCAD.ActiveDocument.Name) + panel = BIM_Library_TaskPanel(offlinemode=libok) + task = FreeCADGui.Control.showDialog(panel) + task.setDocumentName(panel.mainDocName) task.setAutoCloseOnDeletedDocument(True) @@ -554,6 +555,8 @@ class BIM_Library_TaskPanel: if hasattr(self, "box") and self.box: self.box.off() FreeCADGui.Control.closeDialog() + if self.previewDocName in FreeCAD.listDocuments(): + FreeCAD.closeDocument(self.previewDocName) FreeCAD.ActiveDocument.recompute() def insert(self, index=None): @@ -570,8 +573,6 @@ class BIM_Library_TaskPanel: + "\n" ) return - if self.previewDocName in FreeCAD.listDocuments().keys(): - FreeCAD.closeDocument(self.previewDocName) if not index: index = self.form.tree.selectedIndexes() if not index: