TechDraw API: Difference between revisions

From FreeCAD Documentation
m ([[ | ]])
No edit summary
Line 93: Line 93:
dvp.makeCosmeticCircleArc(arcCenter, radius, arcStart, arcEnd, style, weight, shadow)
dvp.makeCosmeticCircleArc(arcCenter, radius, arcStart, arcEnd, style, weight, shadow)


===DrawViewPart Geometry=== <!--T:16-->
[topoShapeEdge] = dvp.getVisibleEdges()

<!--T:17-->
[topoShapeEdge] = dvp.getHideenEdges()





Revision as of 19:00, 12 November 2019

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

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.getHideenEdges()