TechDraw PageTemplate: Difference between revisions

From FreeCAD Documentation
(Removed Version=0.19. Tool exists in V0.17 and maybe even in an earlier version.)
mNo edit summary
 
(24 intermediate revisions by 3 users not shown)
Line 3: Line 3:
<!--T:17-->
<!--T:17-->
{{Docnav
{{Docnav
|[[TechDraw_PageDefault|DefaultPage]]
|[[TechDraw PageDefault|Insert Default Page]]
|[[TechDraw_RedrawPage|Redraw Page]]
|[[TechDraw_RedrawPage|RedrawPage]]
|[[TechDraw_Module|TechDraw]]
|[[TechDraw_Workbench|TechDraw]]
|IconL=TechDraw_PageDefault.svg
|IconL=TechDraw_PageDefault.svg
|IconC=Workbench_TechDraw.svg
|IconR=TechDraw_RedrawPage.svg
|IconR=TechDraw_RedrawPage.svg
|IconC=Workbench_TechDraw.svg
}}
}}


Line 14: Line 14:
{{GuiCommand
{{GuiCommand
|Name=TechDraw PageTemplate
|Name=TechDraw PageTemplate
|MenuLocation=TechDraw → Insert Page using Template
|MenuLocation=TechDraw → Page → Insert Page using Template
|Workbenches=[[TechDraw_Module|TechDraw]]
|Workbenches=[[TechDraw_Workbench|TechDraw]]
|SeeAlso=[[TechDraw_PageDefault|TechDraw Insert Default Page]], [[TechDraw_Templates|TechDraw Templates]]
|SeeAlso=[[TechDraw_PageDefault|TechDraw PageDefault]], [[TechDraw_Templates|TechDraw Templates]]
}}
}}


Line 22: Line 22:


<!--T:8-->
<!--T:8-->
The New Pick tool creates a new Page object using the template file selected from a dialog.
The '''TechDraw PageTemplate''' tool creates a new Page object using the template file selected from a dialog.


<!--T:9-->
<!--T:9-->
The starting directory for the dialog can be specified in the [[TechDraw Preferences|TechDraw Preferences]].
The starting directory for the dialog can be specified in the [[TechDraw_Preferences|TechDraw Preferences]].


</translate>
</translate>
[[Image:A4_Landscape_ISO7200_Pep.svg|400px]]
[[Image:A4_Landscape_ISO7200_Pep.svg|400px]]

<translate>
<translate>
<!--T:10-->
<!--T:10-->
{{Caption|One of the templates that comes with TechDraw: A4 ISO 7200_Pep, page in landscape orientation, with editable text fields}}
{{Caption|One of the templates that comes with TechDraw: A4_Landscape_ISO7200_Pep.svg}}


==Usage== <!--T:3-->
==Usage== <!--T:3-->


<!--T:11-->
<!--T:11-->
# An active document must exist.
* Press the {{Button|[[Image:TechDraw PageTemplate.svg|16px]] [[TechDraw PageTemplate|Insert Page using Template]]}} button
# There are several ways to invoke the tool:
#* Press the {{Button|[[Image:TechDraw_PageTemplate.svg|16px]] [[TechDraw_PageTemplate|Insert Page using Template]]}} button.
#* Select the {{MenuCommand|TechDraw → Page → [[Image:TechDraw_PageTemplate.svg|16px]] Insert Page using Template}} option from the menu.


==Properties== <!--T:5-->
==Properties== <!--T:5-->


<!--T:12-->
<!--T:22-->
See [[TechDraw_PageDefault#Properties|TechDraw PageDefault]].
* {{PropertyData|Projection Type}}: Default projection type (First or Third Angle) for this Page.
* {{PropertyData|Scale}}: Default scale for Views in this Page.


==Scripting== <!--T:6-->
==Scripting== <!--T:6-->


<!--T:13-->
<!--T:13-->
{{Emphasis|See also:}} [[TechDraw API|TechDraw API]] and [[FreeCAD Scripting Basics|FreeCAD Scripting Basics]].
See also: [https://freecad.github.io/SourceDoc/ Autogenerated API documentation] and [[FreeCAD_Scripting_Basics|FreeCAD Scripting Basics]].

<!--T:23-->
A Page based on a selected template can be created with [[Macros|macros]] and from the [[Python|Python]] console by using the following functions:


<!--T:14-->
The New Pick tool can be used in [[macros|macros]] and from the [[Python|Python]] console by using the following functions:
</translate>
</translate>
{{Code|code=
{{Code|code=
import FreeCAD as App
templateFileSpec = QtGui.QFileDialog.getOpenFileName(self.baseWidget,
from PySide import QtGui
dialogCaption,

dialogDir,
doc = App.ActiveDocument
dialogFilter)
default_dir = App.getResourceDir() + "Mod/TechDraw/Templates"
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','Page')
param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/TechDraw/Files")
template = FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
template_dir = param.GetString("TemplateDir", default_dir)
template.Template = templateFileSpec

page.Template = FreeCAD.ActiveDocument.Template
template_file = QtGui.QFileDialog.getOpenFileName(QtGui.QApplication.activeWindow(),
"Select a Template File",
template_dir,
"Template (*.svg)")
page = doc.addObject("TechDraw::DrawPage", "Page")
template = doc.addObject("TechDraw::DrawSVGTemplate", "Template")
template.Template = template_file[0]
page.Template = template

doc.recompute()
}}
}}
<translate>
<translate>
<!--T:7-->
* Creates a new Page in the current document


=== Editable text fields === <!--T:19-->
=== Editable text fields === <!--T:19-->


<!--T:20-->
<!--T:20-->
{{Emphasis|See also:}} [[TechDraw Templates|TechDraw Templates]] for more information on creating templates.
{{Emphasis|See also:}} [[TechDraw_Templates|TechDraw Templates]] for more information on creating templates.

<!--T:24-->
Once a new page has been created, its {{incode|Template}} attribute holds an {{incode|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 {{incode|EditableTexts}} attribute to see the changes.

</translate>
{{Code|code=
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
}}
<translate>


<!--T:21-->
See the information in [[TechDraw_PageDefault|Insert Default Page]] to programmatically change the editable text fields in a page template.


<!--T:18-->
<!--T:18-->
{{Docnav
{{Docnav
|[[TechDraw_PageDefault|Insert Default Page]]
|[[TechDraw_PageDefault|DefaultPage]]
|[[TechDraw_RedrawPage|Redraw Page]]
|[[TechDraw_RedrawPage|RedrawPage]]
|[[TechDraw_Module|TechDraw]]
|[[TechDraw_Workbench|TechDraw]]
|IconL=TechDraw_PageDefault.svg
|IconL=TechDraw_PageDefault.svg
|IconC=Workbench_TechDraw.svg
|IconR=TechDraw_RedrawPage.svg
|IconR=TechDraw_RedrawPage.svg
|IconC=Workbench_TechDraw.svg
}}
}}



Latest revision as of 18:26, 24 July 2023

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.

A Page based on a selected template can be created with macros and from the Python console by using the following functions:

import FreeCAD as App
from PySide import QtGui

doc = App.ActiveDocument
default_dir = App.getResourceDir() + "Mod/TechDraw/Templates"
param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/TechDraw/Files")
template_dir = param.GetString("TemplateDir", default_dir)

template_file = QtGui.QFileDialog.getOpenFileName(QtGui.QApplication.activeWindow(),
                                                  "Select a Template File", 
                                                  template_dir,
                                                  "Template (*.svg)")
                                                  
page = doc.addObject("TechDraw::DrawPage", "Page")
template = doc.addObject("TechDraw::DrawSVGTemplate", "Template")
template.Template = template_file[0]
page.Template = template

doc.recompute()

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