diff --git a/src/Mod/TechDraw/TechDrawTools/CommandFillTemplateFields.py b/src/Mod/TechDraw/TechDrawTools/CommandFillTemplateFields.py index 3ec1ab5759..00c7afca3e 100644 --- a/src/Mod/TechDraw/TechDrawTools/CommandFillTemplateFields.py +++ b/src/Mod/TechDraw/TechDrawTools/CommandFillTemplateFields.py @@ -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 + # diff --git a/src/Mod/TechDraw/TechDrawTools/TaskFillTemplateFields.py b/src/Mod/TechDraw/TechDrawTools/TaskFillTemplateFields.py index d39de1b0ca..d7c2c4b859 100644 --- a/src/Mod/TechDraw/TechDrawTools/TaskFillTemplateFields.py +++ b/src/Mod/TechDraw/TechDrawTools/TaskFillTemplateFields.py @@ -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"): - projgrp_view = self.page.Views[0] + if ( + pageObj.isDerivedFrom("TechDraw::DrawViewPart") + or pageObj.isDerivedFrom("TechDraw::DrawProjGroup") + ): + # use the scale from the first DVP or DPG encountered to fill the template's + # Scale editable text. + projgrp_view = pageObj + break self.texts = self.page.Template.EditableTexts @@ -429,7 +433,7 @@ class TaskFillTemplateFields: self.dialog.show() self.dialog.exec_() - App.setActiveTransaction("Fill template fields") +# App.setActiveTransaction("Fill template fields") else: msgBox = QtGui.QMessageBox() msgTitle = QtCore.QT_TRANSLATE_NOOP( @@ -520,17 +524,19 @@ class TaskFillTemplateFields: self.button.setEnabled(False) def proceed(self): + transactionName = QtCore.QT_TRANSLATE_NOOP("Techdraw_FillTemplateFields", "Fill template fields") + App.setActiveTransaction(transactionName) i = 0 for cb in self.checkBoxList: if cb.isChecked(): self.texts[keyLst[i]] = self.lineTextList[i].text() i += 1 self.page.Template.EditableTexts = self.texts + App.closeActiveTransaction(False) self.close() App.closeActiveTransaction() def close(self): self.dialog.hide() - App.closeActiveTransaction(True) return True