TechDraw API: Difference between revisions

From FreeCAD Documentation
(Better links)
(Cleanup code)
Line 13: Line 13:
import FreeCAD
import FreeCAD
import TechDraw
import TechDraw

page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage', 'Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate', 'Template')
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
page.ViewObject.show()
page.ViewObject.show()
view = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart','View')
view = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart', 'View')
rc = page.addView(view)
rc = page.addView(view)
}}
}}
Line 28: Line 29:
{{APIFunction|findOuterWire|listOfEdges|Finds the OuterWire (largest) of a list of edges (that form a planar graph).|Outer wire}}
{{APIFunction|findOuterWire|listOfEdges|Finds the OuterWire (largest) of a list of edges (that form a planar graph).|Outer wire}}
{{APIFunction|findShapeOutline|TopoShape, scale, direction|Project shape in direction and find outer wire of result.|Outline wire}}
{{APIFunction|findShapeOutline|TopoShape, scale, direction|Project shape in direction and find outer wire of result.|Outline wire}}

{{APIFunction|viewPartAsDxf|DrawViewPart|Return the edges of a DrawViewPart in Dxf format.|String}}
{{APIFunction|viewPartAsDxf|DrawViewPart|Return the edges of a DrawViewPart in Dxf format.|String}}
Example{{Code|code=
Example:
{{Code|code=
fileSpecDxf = "fcOut.dxf"
fileSpecDxf = "fcOut.dxf"
v = App.ActiveDocument.View
v = App.ActiveDocument.View
Line 39: Line 42:
dxfFile.close()
dxfFile.close()
}}
}}

{{APIFunction|viewPartAsSvg|DrawViewPart|Return the edges of a DrawViewPart in Svg format.|String}}
{{APIFunction|viewPartAsSvg|DrawViewPart|Return the edges of a DrawViewPart in Svg format.|String}}
Example{{Code|code=
Example:
{{Code|code=
fileSpecSvg = "fcOut.svg"
fileSpecSvg = "fcOut.svg"
v = App.ActiveDocument.View
v = App.ActiveDocument.View
Line 54: Line 59:
svgFile.close()
svgFile.close()
}}
}}

{{APIFunction|writeDXFView|DrawViewPart, FileName|Save the DrawViewPart in Dxf.|File}}
{{APIFunction|writeDXFView|DrawViewPart, FileName|Save the DrawViewPart in Dxf.|File}}
Example{{Code|code=
Example:
{{Code|code=
import TechDraw
import TechDraw
TechDraw.writeDXFView(myPart,myFileName)
TechDraw.writeDXFView(myPart,myFileName)
}}
}}

{{APIFunction|writeDXFPage|DrawPage, FileName|Save the DrawPage in Dxf.|File}}
{{APIFunction|writeDXFPage|DrawPage, FileName|Save the DrawPage in Dxf.|File}}
Example{{Code|code=
Example:
{{Code|code=
import TechDraw
import TechDraw
TechDraw.writeDXFPage(myPage,myFileName)
TechDraw.writeDXFPage(myPage,myFileName)

Revision as of 04:48, 27 October 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 Workbench 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)


EdgeWalker(listOfEdges, [bool])

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)

findOuterWire(listOfEdges)

Description: Finds the OuterWire (largest) of a list of edges (that form a planar graph).

Returns: Outer wire

findShapeOutline(TopoShape, scale, direction)

Description: Project shape in direction and find outer wire of result.

Returns: Outline wire

viewPartAsDxf(DrawViewPart)

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()
viewPartAsSvg(DrawViewPart)

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()
writeDXFView(DrawViewPart, FileName)

Description: Save the DrawViewPart in Dxf.

Returns: File

Example:

import TechDraw
TechDraw.writeDXFView(myPart,myFileName)
writeDXFPage(DrawPage, FileName)

Description: Save the DrawPage in Dxf.

Returns: File

Example:

import TechDraw
TechDraw.writeDXFPage(myPage,myFileName)


Back to TechDraw.