[TD]defend against deleted object error

- App.ActiveDocument.Objects was returning a deleted object
  Most likely due to shenanigans with DrawViewPart/DrawProjGroup item
  in TaskProjGroup.
This commit is contained in:
wandererfan
2025-10-20 18:42:28 -04:00
parent cf9bb8bb16
commit 2709d2a595
2 changed files with 42 additions and 36 deletions

View File

@@ -62,37 +62,39 @@ class CommandFillTemplateFields:
"""Return True when the command should be active
or False when it should be disabled (greyed)."""
if App.ActiveDocument:
objs = App.ActiveDocument.Objects
objs = App.ActiveDocument.findObjects(Type="TechDraw::DrawPage")
if not objs:
return false
for obj in objs:
if obj.TypeId == "TechDraw::DrawPage":
file_path = (
App.getResourceDir()
+ "Mod/TechDraw/CSVdata/FillTemplateFields.csv"
)
if os.path.exists(file_path):
listofkeys = [
"CreatedByChkLst",
"ScaleChkLst",
"LabelChkLst",
"CommentChkLst",
"CompanyChkLst",
"LicenseChkLst",
"CreatedDateChkLst",
"LastModifiedDateChkLst",
]
with codecs.open(file_path, encoding="utf-8") as fp:
reader = csv.DictReader(fp)
page = obj
texts = page.Template.EditableTexts
if (
texts
and os.path.exists(file_path)
and listofkeys == reader.fieldnames
and obj.Views != []
):
return True
else:
return False
file_path = (
App.getResourceDir()
+ "Mod/TechDraw/CSVdata/FillTemplateFields.csv"
)
if os.path.exists(file_path):
listofkeys = [
"CreatedByChkLst",
"ScaleChkLst",
"LabelChkLst",
"CommentChkLst",
"CompanyChkLst",
"LicenseChkLst",
"CreatedDateChkLst",
"LastModifiedDateChkLst",
]
with codecs.open(file_path, encoding="utf-8") as fp:
reader = csv.DictReader(fp)
page = obj
texts = page.Template.EditableTexts
if (
texts
and os.path.exists(file_path)
and listofkeys == reader.fieldnames
and obj.Views != []
):
return True
return false
#

View File

@@ -91,11 +91,11 @@ keyLst = []
class TaskFillTemplateFields:
def __init__(self):
objs = App.ActiveDocument.Objects
objs = App.ActiveDocument.findObjects(Type="TechDraw::DrawPage")
for obj in objs:
if (
obj.TypeId == "TechDraw::DrawPage"
and os.path.exists(file_path)
os.path.exists(file_path)
and listofkeys == reader.fieldnames
):
self.page = obj
@@ -117,10 +117,14 @@ class TaskFillTemplateFields:
projgrp_view = None
for pageObj in obj.Views:
if pageObj.isDerivedFrom("TechDraw::DrawViewPart"):
projgrp_view = self.page.Views[0]
elif pageObj.isDerivedFrom("TechDraw::DrawProjGroup"):
if (
pageObj.isDerivedFrom("TechDraw::DrawViewPart")
or pageObj.isDerivedFrom("TechDraw::DrawProjGroup")
):
# should this not be pageObj? this is looking for any DVP or DPG on the page?
# Views[0] could be an annotation or symbol or ??? - WF
projgrp_view = self.page.Views[0]
break
self.texts = self.page.Template.EditableTexts