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.
This commit is contained in:
Roy-043
2024-10-22 11:47:37 +02:00
parent 68be845a68
commit 6c9ea36225
2 changed files with 10 additions and 5 deletions

View File

@@ -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

View File

@@ -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