TechDraw API: Difference between revisions
Renatorivo (talk | contribs) (Marked this version for translation) |
(Message for outdated API) |
||
Line 2: | Line 2: | ||
<translate> |
<translate> |
||
<!--T:1--> |
<!--T:1--> |
||
{{VeryImportantMessage|(November 2018) This information may be incomplete and outdated. For the latest API, see the [https://www.freecadweb.org/api autogenerated API documentation].}} |
|||
These functions are part of the [[TechDraw Workbench]] and can be used in scripts and [[macros]] or from the [[Python]] interpreter, once the |
These functions are part of the [[TechDraw Workbench]] and can be used in scripts and [[macros]] or from the [[Python]] interpreter, once the {{incode|TechDraw}} module has been imported. Good examples of basic TechDraw scripting can be found in the [https://github.com/FreeCAD/FreeCAD/tree/master/src/Mod/TechDraw/TDTest unit test scripts]. |
||
<!--T:5--> |
<!--T:5--> |
||
Line 22: | Line 23: | ||
rc = page.addView(view) |
rc = page.addView(view) |
||
}} |
}} |
||
<translate> |
<translate> |
Revision as of 13:55, 24 November 2018
These functions are part of the TechDraw Workbench and can be used in scripts and macros or from the Python interpreter, once the TechDraw
module has been imported. Good examples of basic TechDraw scripting can be found in the unit test scripts.
See the TechDrawGui API for more functions.
Example:
import FreeCAD
import TechDraw
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage', 'Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate', 'Template')
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
page.ViewObject.show()
view = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart', 'View')
rc = page.addView(view)
Description: Creates wires from edges in input by planar graph traversal. Optionally exclude the OuterWire by setting optional parameter to false.
Returns: List of wires sorted by size (descending)
Description: Finds the OuterWire (largest) of a list of edges (that form a planar graph).
Returns: Outer wire
Description: Project shape in direction and find outer wire of result.
Returns: Outline wire
Description: Return the edges of a DrawViewPart in Dxf format.
Returns: String
Example:
fileSpecDxf = "fcOut.dxf"
v = App.ActiveDocument.View
s = TechDraw.viewPartAsDxf(v)
dxfEnd = "0\nEOF\n"
dxfFile = open(fileSpecDxf, "w")
dxfFile.write(s)
dxfFile.write(dxfEnd)
dxfFile.close()
Description: Return the edges of a DrawViewPart in Svg format.
Returns: String
Example:
fileSpecSvg = "fcOut.svg"
v = App.ActiveDocument.View
s = TechDraw.viewPartAsSvg(v)
head = '<svg\n' + \
' xmlns="http://www.w3.org/2000/svg" version="1.1" \n' + \
' xmlns:freecad="http://www.freecadweb.org/wiki/index.php?title=Svg_Namespace">\n'
tail = '\n</svg>'
svgFile = open(fileSpecSvg, "w")
svgFile.write(head)
svgFile.write(s)
svgFile.write(tail)
svgFile.close()
Example:
import TechDraw
TechDraw.writeDXFView(myPart,myFileName)
Example:
import TechDraw
TechDraw.writeDXFPage(myPage,myFileName)
Back to the TechDraw Workbench.