TechDraw PageTemplate

From FreeCAD Documentation
Revision as of 14:20, 24 July 2023 by Roy 043 (talk | contribs) (Scripting)

TechDraw PageTemplate

Menu location
TechDraw → Page → Insert Page using Template
Workbenches
TechDraw
Default shortcut
None
Introduced in version
-
See also
TechDraw PageDefault, TechDraw Templates

Description

The TechDraw PageTemplate tool creates a new Page object using the template file selected from a dialog.

The starting directory for the dialog can be specified in the TechDraw Preferences.

One of the templates that comes with TechDraw: A4_Landscape_ISO7200_Pep.svg

Usage

  1. An active document must exist.
  2. There are several ways to invoke the tool:

Properties

See TechDraw PageDefault.

Scripting

See also: Autogenerated API documentation and FreeCAD Scripting Basics.

The New Pick tool can be used in macros and from the Python console by using the following functions:

templateFileSpec = QtGui.QFileDialog.getOpenFileName(self.baseWidget,
                                                     dialogCaption, 
                                                     dialogDir,
                                                     dialogFilter)
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','Page')
template = FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
template.Template = templateFileSpec
page.Template = FreeCAD.ActiveDocument.Template
  • Creates a new Page in the current document

Editable text fields

See also: TechDraw Templates for more information on creating templates.

Once a new page has been created, its Template attribute holds an EditableTexts dictionary with the name of the editable fields (keys) and their textual values. Copy this dictionary to a variable, make changes, and then re-assign the dictionary to the EditableTexts attribute to see the changes.

page = FreeCAD.ActiveDocument.Page
texts = page.Template.EditableTexts

for key, value in texts.items():
    print("{0} = {1}".format(key, value))

texts["FC-Title"] = "The title of my page"
page.Template.EditableTexts = texts