From 6c9ea3622588384c454dd9e511b708b38433c01e Mon Sep 17 00:00:00 2001 From: Roy-043 Date: Tue, 22 Oct 2024 11:47:37 +0200 Subject: [PATCH] Restore the ViewObject I think we need to restore the ViewObject in such cases. I assume this problems exists for all Draft and BIM objects. So this commit is just an example implementation. --- src/Mod/Draft/draftobjects/draft_annotation.py | 6 +++--- src/Mod/Draft/draftobjects/label.py | 9 +++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Mod/Draft/draftobjects/draft_annotation.py b/src/Mod/Draft/draftobjects/draft_annotation.py index 53670c1309..b8488af939 100644 --- a/src/Mod/Draft/draftobjects/draft_annotation.py +++ b/src/Mod/Draft/draftobjects/draft_annotation.py @@ -59,12 +59,12 @@ class DraftAnnotation(object): Check if new properties are present after the object is restored in order to migrate older objects. """ - if not hasattr(obj, "ViewObject"): + if not getattr(obj, "ViewObject", None): return vobj = obj.ViewObject - if not vobj: - return if not getattr(vobj, "Proxy", None): + # Object was save without GUI. + # onDocumentRestored in the object class should restore the ViewObject. return if hasattr(vobj, "ScaleMultiplier") and hasattr(vobj, "AnnotationStyle"): return diff --git a/src/Mod/Draft/draftobjects/label.py b/src/Mod/Draft/draftobjects/label.py index 72a1cdcc85..4604466cde 100644 --- a/src/Mod/Draft/draftobjects/label.py +++ b/src/Mod/Draft/draftobjects/label.py @@ -227,10 +227,15 @@ class Label(DraftAnnotation): super().onDocumentRestored(obj) self.Type = "Label" - if not hasattr(obj, "ViewObject"): + if not getattr(obj, "ViewObject", None): return vobj = obj.ViewObject - if not vobj: + if not getattr(vobj, "Proxy", None): + # Object was save without GUI. We need to restore the ViewObject. + from draftviewproviders.view_label import ViewProviderLabel + from draftutils import gui_utils + ViewProviderLabel(obj.ViewObject) + gui_utils.format_object(obj) return if hasattr(vobj, "FontName") and hasattr(vobj, "FontSize"): return