Skip to content

Commit

Permalink
Draft: better checks for no active document
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Nov 16, 2020
1 parent ec3bbb0 commit bff3117
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
11 changes: 6 additions & 5 deletions src/Mod/Draft/WorkingPlane.py
Expand Up @@ -777,11 +777,12 @@ def getRotation(self):
# 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):
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Draft/draftguitools/gui_snapper.py
Expand Up @@ -1659,7 +1659,7 @@ def setGrid(self):
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]
Expand Down
25 changes: 13 additions & 12 deletions src/Mod/Draft/draftutils/gui_utils.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit bff3117

Please sign in to comment.