From bff31175cbb793e457baaf4ed2964e2683b698ca Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Mon, 16 Nov 2020 13:25:12 +0100 Subject: [PATCH] Draft: better checks for no active document --- src/Mod/Draft/WorkingPlane.py | 11 +++++----- src/Mod/Draft/draftguitools/gui_snapper.py | 2 +- src/Mod/Draft/draftutils/gui_utils.py | 25 +++++++++++----------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/Mod/Draft/WorkingPlane.py b/src/Mod/Draft/WorkingPlane.py index b09e061f98..408ce7677b 100644 --- a/src/Mod/Draft/WorkingPlane.py +++ b/src/Mod/Draft/WorkingPlane.py @@ -777,11 +777,12 @@ class Plane: # Arch active container if FreeCAD.GuiUp: import FreeCADGui - view = FreeCADGui.ActiveDocument.ActiveView - if view: - a = view.getActiveObject("Arch") - if a: - p = a.Placement.inverse().multiply(p) + if FreeCADGui.ActiveDocument: + view = FreeCADGui.ActiveDocument.ActiveView + if view: + a = view.getActiveObject("Arch") + if a: + p = a.Placement.inverse().multiply(p) return p def getPlacement(self, rotated=False): diff --git a/src/Mod/Draft/draftguitools/gui_snapper.py b/src/Mod/Draft/draftguitools/gui_snapper.py index a6005ceb59..7d1233993b 100644 --- a/src/Mod/Draft/draftguitools/gui_snapper.py +++ b/src/Mod/Draft/draftguitools/gui_snapper.py @@ -1659,7 +1659,7 @@ class Snapper: def setTrackers(self): """Set the trackers.""" v = Draft.get3DView() - if v != self.activeview: + if v and (v != self.activeview): if v in self.trackers[0]: i = self.trackers[0].index(v) self.grid = self.trackers[1][i] diff --git a/src/Mod/Draft/draftutils/gui_utils.py b/src/Mod/Draft/draftutils/gui_utils.py index 5d010c956f..a28071c2ba 100644 --- a/src/Mod/Draft/draftutils/gui_utils.py +++ b/src/Mod/Draft/draftutils/gui_utils.py @@ -65,14 +65,15 @@ def get_3d_view(): Return `None` if the graphical interface is not available. """ if App.GuiUp: - v = Gui.ActiveDocument.ActiveView - if "View3DInventor" in str(type(v)): - return v + if Gui.ActiveDocument: + v = Gui.ActiveDocument.ActiveView + if "View3DInventor" in str(type(v)): + return v - # print("Debug: Draft: Warning, not working in active view") - v = Gui.ActiveDocument.mdiViewsOfType("Gui::View3DInventor") - if v: - return v[0] + # print("Debug: Draft: Warning, not working in active view") + v = Gui.ActiveDocument.mdiViewsOfType("Gui::View3DInventor") + if v: + return v[0] _wrn(_tr("No graphical interface")) return None @@ -100,17 +101,17 @@ def autogroup(obj): obj: App::DocumentObject Any type of object that will be stored in the group. """ - + # check for required conditions for autogroup to work if not App.GuiUp: return if not hasattr(Gui,"draftToolBar"): return if not hasattr(Gui.draftToolBar,"autogroup"): - return + return if Gui.draftToolBar.isConstructionMode(): return - + # autogroup code if Gui.draftToolBar.autogroup is not None: active_group = App.ActiveDocument.getObject(Gui.draftToolBar.autogroup) @@ -123,13 +124,13 @@ def autogroup(obj): gr = active_group.Group gr.append(obj) active_group.Group = gr - + else: if Gui.ActiveDocument.ActiveView.getActiveObject("Arch"): # add object to active Arch Container Gui.ActiveDocument.ActiveView.getActiveObject("Arch").addObject(obj) - + elif Gui.ActiveDocument.ActiveView.getActiveObject("part", False) is not None: # add object to active part and change it's placement accordingly # so object does not jump to different position, works with App::Link