| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | """Provides the TechDraw FillTemplateFields GuiCommand.""" |
| |
|
| | __title__ = "TechDrawTools.CommandFillTemplateFields" |
| | __author__ = "Syres" |
| | __url__ = "https://www.freecad.org" |
| | __version__ = "00.02" |
| | __date__ = "2023/12/07" |
| |
|
| | from PySide.QtCore import QT_TRANSLATE_NOOP |
| |
|
| | import FreeCAD as App |
| | import FreeCADGui as Gui |
| | import codecs |
| | import csv |
| | import os.path |
| |
|
| | import TechDrawTools |
| |
|
| |
|
| | class CommandFillTemplateFields: |
| | """Use document info to populate the template fields.""" |
| |
|
| | def GetResources(self): |
| | """Return a dictionary with data that will be used by the button or menu item.""" |
| | return { |
| | "Pixmap": "actions/TechDraw_FillTemplateFields.svg", |
| | "Accel": "", |
| | "MenuText": QT_TRANSLATE_NOOP( |
| | "TechDraw_FillTemplateFields", "Update Template Fields" |
| | ), |
| | "ToolTip": QT_TRANSLATE_NOOP( |
| | "TechDraw_FillTemplateFields", |
| | "Uses document info to populate the template fields", |
| | ), |
| | } |
| |
|
| | def Activated(self): |
| | """Run the following code when the command is activated (button press).""" |
| | TechDrawTools.TaskFillTemplateFields() |
| |
|
| | def IsActive(self): |
| | """Return True when the command should be active |
| | or False when it should be disabled (greyed).""" |
| | if App.ActiveDocument: |
| | objs = App.ActiveDocument.findObjects(Type="TechDraw::DrawPage") |
| | if not objs: |
| | return false |
| |
|
| | for obj in objs: |
| | 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 |
| |
|
| |
|
| |
|
| | |
| | |
| | Gui.addCommand("TechDraw_FillTemplateFields", CommandFillTemplateFields()) |
| |
|
| |
|