Difference between revisions of "TechDraw API"

From FreeCAD Documentation
Jump to: navigation, search
 
Line 97: Line 97:
  
 
<!--T:17-->
 
<!--T:17-->
[topoShapeEdge] = dvp.getHideenEdges()
+
[topoShapeEdge] = dvp.getHiddenEdges()
  
  

Latest revision as of 20:00, 12 November 2019

Other languages:
Deutsch • ‎English • ‎français • ‎italiano • ‎română
(November 2018) This information may be incomplete and outdated. For the latest API, see the autogenerated API documentation.

These functions are part of the TechDraw Workbench and can be used in macros and from the Python console 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)
Method.png 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)

Method.png findOuterWire(listOfEdges)

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

Returns: Outer wire

Method.png findShapeOutline(TopoShape, scale, direction)

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

Returns: Outline wire

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

Description: Save the DrawViewPart in Dxf.

Returns: File

Example:

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

Description: Save the DrawPage in Dxf.

Returns: File

Example:

import TechDraw
TechDraw.writeDXFPage(myPage,myFileName)

DrawViewPart Cosmetics

dvp.makeCosmeticVertex(point)

dvp.makeCosmeticLine(start,end,style, weight, pyGreen)

dvp.makeCosmeticCircle(center, radius, style, weight, pyRed)

dvp.makeCosmeticCircleArc(arcCenter, radius, arcStart, arcEnd, style, weight, shadow)

DrawViewPart Geometry

[topoShapeEdge] = dvp.getVisibleEdges()

[topoShapeEdge] = dvp.getHiddenEdges()