TechDraw API: Difference between revisions

From FreeCAD Documentation
No edit summary
No edit summary
 
(15 intermediate revisions by 4 users not shown)
Line 3: Line 3:
<!--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].}}
{{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|TechDraw Workbench]] and can be used in [[macros|macros]] and from the [[Python|Python]] console once the {{incode|TechDraw}} module has been imported.
These functions are part of the [[TechDraw_Workbench|TechDraw Workbench]] and can be used in [[Macros|macros]] and from the [[Python|Python]] console once the {{incode|TechDraw}} module has been imported.


<!--T:11-->
<!--T:11-->
Line 13: Line 13:
<!--T:2-->
<!--T:2-->
Example:
Example:

</translate>
</translate>
{{Code|code=
{{Code|code=
Line 29: Line 30:
<translate>
<translate>
<!--T:3-->
<!--T:3-->
{{APIFunction|EdgeWalker|listOfEdges, [bool]|Creates wires from edges in input by planar graph traversal. Optionally exclude the OuterWire by setting optional parameter to false.|List of wires sorted by size (descending)}}
{{APIFunction|EdgeWalker|listOfEdges, [bool]|Creates wires from edges in input by planar graph traversal. Optionally exclude the OuterWire by setting optional parameter to false.|List of wires sorted by size (descending)}}
{{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}}
Line 36: Line 37:
{{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:
Example:

</translate>
{{Code|code=
{{Code|code=
fileSpecDxf = "fcOut.dxf"
fileSpecDxf = "fcOut.dxf"
Line 46: Line 49:
dxfFile.close()
dxfFile.close()
}}
}}
<translate>


<!--T:8-->
<!--T:8-->
{{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:
Example:

</translate>
{{Code|code=
{{Code|code=
fileSpecSvg = "fcOut.svg"
fileSpecSvg = "fcOut.svg"
Line 64: Line 70:
svgFile.close()
svgFile.close()
}}
}}
<translate>


<!--T:9-->
<!--T:9-->
{{APIFunction|writeDXFView|DrawViewPart, FileName|Save the DrawViewPart in Dxf.|File}}
{{APIFunction|writeDXFView|DrawViewPart, FileName|Save the DrawViewPart in Dxf.|File}}
Example:
Example:

</translate>
{{Code|code=
{{Code|code=
import TechDraw
import TechDraw
TechDraw.writeDXFView(myPart,myFileName)
TechDraw.writeDXFView(myPart,myFileName)
}}
}}
<translate>


<!--T:10-->
<!--T:10-->
{{APIFunction|writeDXFPage|DrawPage, FileName|Save the DrawPage in Dxf.|File}}
{{APIFunction|writeDXFPage|DrawPage, FileName|Save the DrawPage in Dxf.|File}}
Example:
Example:

</translate>
{{Code|code=
{{Code|code=
import TechDraw
import TechDraw
TechDraw.writeDXFPage(myPage,myFileName)
TechDraw.writeDXFPage(myPage,myFileName)
}}
}}
<translate>


===DrawViewPart Cosmetics=== <!--T:12-->
===DrawViewPart Cosmetics=== <!--T:12-->


====CosmeticVertex (CV) routines accessible from Python====
====CosmeticVertex (CV) routines accessible from Python==== <!--T:18-->


<!--T:19-->
#dvp = App.ActiveDocument.View #CV's belong to views
dvp = App.ActiveDocument.View #CV's belong to views.<br>


<!--T:20-->
# add a CosmeticVertex at p1 (View coordinates). Returns unique tag.
Add a CosmeticVertex at p1 (View coordinates). Returns unique tag.<br>
tag = dvp.makeCosmeticVertex(vector p1)
tag = dvp.makeCosmeticVertex(vector p1)


<!--T:21-->
# add a CosmeticVertex at p1 (3d model coordinates). Returns unique tag.
Add a CosmeticVertex at p1 (3d model coordinates). Returns unique tag.<br>
tag = dvp.makeCosmeticVertex3d(vector p1)
tag = dvp.makeCosmeticVertex3d(vector p1)


<!--T:22-->
# returns CosmeticVertex with unique id.
Returns CosmeticVertex with unique id.<br>
cv = dvp.getCosmeticVertex(string id)
cv = dvp.getCosmeticVertex(string id)


<!--T:23-->
# returns CosmeticVertex with name (Vertex6). Used in selections.
Returns CosmeticVertex with name (Vertex6). Used in selections.<br>
cv = dvp.getCosmeticVertexBySelection(string name)
cv = dvp.getCosmeticVertexBySelection(string name)


<!--T:25-->
# replaces CosmeticVertex in View. Returns True/False.
Removes CosmeticVertex from View. Returns None.<br>
bool = dvp.replaceCosmeticVertex(object cv)

# remove CosmeticVertex from View. Returns None.
dvp.removeCosmeticVertex(object cv)
dvp.removeCosmeticVertex(object cv)


<!--T:26-->
# remove all CosmeticVertices from the View. Returns None.
Removes all CosmeticVertices from the View. Returns None.<br>
dvp.clearCosmeticVertices()
dvp.clearCosmeticVertices()


<!--T:27-->
CosmeticView attributes
CosmeticView attributes<br>
Tag: unique identifier. String.
Tag: unique identifier. String.<br>
Point: location within view. Vector.
Point: location within view. Vector.<br>


</translate>
<!--T:28-->
********************************************************************************
********************************************************************************
{{Code|code=

#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-


<!--T:29-->
# Py CosmeticVertex demo
# Py CosmeticVertex demo
import FreeCAD
import FreeCAD
import TechDraw
import TechDraw


<!--T:30-->
v = App.ActiveDocument.View
v = App.ActiveDocument.View
p = App.Vector(-3.0, -3.0, 0.0)
p = App.Vector(-3.0, -3.0, 0.0)


<!--T:31-->
#make CV
#make CV
tag = v.makeCosmeticVertex(p)
tag = v.makeCosmeticVertex(p)
print("t: {}".format(tag))
print("t: {}".format(tag))


<!--T:32-->
#retrieve CV
#retrieve CV
cv = v.getCosmeticVertex(tag)
cv = v.getCosmeticVertex(tag)
Line 133: Line 157:
print("Tag: {}".format(cv.Tag))
print("Tag: {}".format(cv.Tag))


#replace CV
p2 = App.Vector(4.0, 3.0, 0.0)
cv.Point = p2
v.replaceCosmeticVertex(cv)


<!--T:34-->
cv2 = v.getCosmeticVertexBySelection("Vertex4")
cv2 = v.getCosmeticVertexBySelection("Vertex4")
print("New Point: {}".format(cv2.Point))
print("New Point: {}".format(cv2.Point))


<!--T:35-->
#make CV from 3d
#make CV from 3d
p3d = App.Vector(2.0, 2.0, 2.0)
p3d = App.Vector(2.0, 2.0, 2.0)
Line 147: Line 169:
cv3 = v.getCosmeticVertex(tag3d)
cv3 = v.getCosmeticVertex(tag3d)
print("3d point out: {}".format(cv3.Point))
print("3d point out: {}".format(cv3.Point))
}}


<translate>
====CosmeticEdge (CE) routines accessible from Python==== <!--T:36-->


<!--T:37-->
====CosmeticEdge (CE) routines accessible from Python====
dvp = App.ActiveDocument.View #CE's belong to views.<br>


<!--T:38-->
#dvp = App.ActiveDocument.View #CE's belong to views
Make a CosmeticEdge from p1 to p2(View coordinates). Returns unique tag.<br>

# Make a CosmeticEdge from p1 to p2(View coordinates). Returns unique tag.
tag = dvp.makeCosmeticLine(p1, p2)
tag = dvp.makeCosmeticLine(p1, p2)


<!--T:39-->
# Make a CosmeticEdge at center with radius radius(View coordinates). Returns unique tag.
Make a CosmeticEdge at center with radius radius(View coordinates). Returns unique tag.<br>
tag = dvp.makeCosmeticCircle(center, radius)
tag = dvp.makeCosmeticCircle(center, radius)


<!--T:40-->
# Make a CosmeticEdge at center with radius radius(View coordinates) from start angle to end angle. Returns unique tag.
Make a CosmeticEdge at center with radius radius(View coordinates) from start angle to end angle. Returns unique tag.<br>
tag = dvp.makeCosmeticCircleArc(center, radius, start, end)
tag = dvp.makeCosmeticCircleArc(center, radius, start, end)


<!--T:41-->
# returns CosmeticEdge with unique id.
Returns CosmeticEdge with unique id.<br>
ce = dvp.getCosmeticEdge(id)
ce = dvp.getCosmeticEdge(id)


<!--T:42-->
# returns CosmeticEdge by name (Edge25). Used in selections
Returns CosmeticEdge by name (Edge25). Used in selections.<br>
ce = dvp.getCosmeticEdgeBySelection(name)
ce = dvp.getCosmeticEdgeBySelection(name)


<!--T:44-->
# replace CosmeticEdge ce in dvp PropertyCosmeticEdgeList. ce.Tag must match an existing tag
Removes CosmeticEdge ce from View. Returns None.<br>
bool = dvp.replaceCosmeticEdge(ce)

# remove CosmeticEdge ce from View. Returns None.
dvp.removeCosmeticEdge(ce)
dvp.removeCosmeticEdge(ce)


<!--T:45-->
# remove all CosmeticLines from the View. Returns None.
Removes all CosmeticLines from the View. Returns None.<br>
dvp.clearCosmeticEdges()
dvp.clearCosmeticEdges()


<!--T:46-->
CosmeticEdge attributes
CosmeticEdge attributes<br>
Tag: unique identifier. String.
Tag: unique identifier. String.<br>
Format: appearance attributes (style, color, weight, visible). Tuple.
Format: appearance attributes (style, color, weight, visible). Tuple.<br>


</translate>
<!--T:47-->
********************************************************************************
********************************************************************************
{{Code|code=

#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-


<!--T:48-->
# Py CosmeticEdge demo
# Py CosmeticEdge demo
import FreeCAD
import FreeCAD
import TechDraw
import TechDraw


<!--T:49-->
#points
#points
org = App.Vector(0.0, 0.0, 0.0)
org = App.Vector(0.0, 0.0, 0.0)
Line 201: Line 234:
bottomLeft = FreeCAD.Vector(-5.0, -5.0, 0.0)
bottomLeft = FreeCAD.Vector(-5.0, -5.0, 0.0)


<!--T:50-->
#angles
#angles
arcStart = -45
arcStart = -45
arcEnd = 45
arcEnd = 45


<!--T:51-->
#styles
#styles
solid = 1
solid = 1
Line 219: Line 254:
shadow = (0.1, 0.1, 0.1, 0.0)
shadow = (0.1, 0.1, 0.1, 0.0)


<!--T:52-->
radius = 5.0
radius = 5.0
style = dashed
style = dashed
weight = weight75
weight = weight75


<!--T:53-->
dvp = App.ActiveDocument.View
dvp = App.ActiveDocument.View


<!--T:54-->
print(dvp)
print(dvp)


<!--T:55-->
print("making line")
print("making line")
tag = dvp.makeCosmeticLine(midTop,midBot,style, weight, pyBlue)
tag = dvp.makeCosmeticLine(midTop,midBot,style, weight, pyBlue)
Line 232: Line 271:
print("line tag: {}".format(tag))
print("line tag: {}".format(tag))


<!--T:56-->
print("making diagonal")
print("making diagonal")
dvp.makeCosmeticLine(bottomLeft,topRight,solid, weight, pyGreen)
dvp.makeCosmeticLine(bottomLeft,topRight,solid, weight, pyGreen)


<!--T:57-->
print("making circle")
print("making circle")
tag2 = dvp.makeCosmeticCircle(center, radius, style, weight, pyRed)
tag2 = dvp.makeCosmeticCircle(center, radius, style, weight, pyRed)
ce2 = dvp.getCosmeticEdge(tag2)
ce2 = dvp.getCosmeticEdge(tag2)


<!--T:58-->
print("making circleArc")
print("making circleArc")
dvp.makeCosmeticCircleArc(arcCenter, radius, arcStart, arcEnd, style, weight, shadow)
dvp.makeCosmeticCircleArc(arcCenter, radius, arcStart, arcEnd, style, weight, shadow)


<!--T:59-->
#replace
#replace
print("making new format")
print("making new format")
Line 248: Line 291:
ce.Format = newFormat
ce.Format = newFormat


<!--T:61-->
print("replacing CE with tag: {}".format(ce.Tag))
ce = dvp.getCosmeticEdge(tag)
rc = dvp.replaceCosmeticEdge(ce)
print("replace returns: {}".format(rc))

print("removing CE with tag: {}".format(tag2))
print("removing CE with tag: {}".format(tag2))
dvp.removeCosmeticEdge(tag2)
dvp.removeCosmeticEdge(tag2)


<!--T:62-->
print("finished")
print("finished")
}}


<translate>
====CenterLine (CL) routines accessible from Python==== <!--T:63-->


<!--T:64-->
====CenterLine (CL) routines accessible from Python====
Makes a new CenterLine<br>
tag = dvp.makeCenterLine(subObjs, mode)<br>


<!--T:65-->
# make a new CenterLine
Retrieves CenterLine with unique tag.<br>
tag = dvp.makeCenterLine(subObjs, mode)

# retrieve CenterLine with unique tag
cl = dvp.getCenterLine(tag)
cl = dvp.getCenterLine(tag)


<!--T:66-->
# retrieve CenterLine by subobject name. Used in selection.
Retrieves CenterLine by subobject name. Used in selection.<br>
cl = dvp.getCenterLine("Edge5")
cl = dvp.getCenterLine("Edge5")


<!--T:68-->
# replace CenterLine cl in dvp PropertyCenterLineList. cl.Tag must match an existing tag
Removes CenterLine cl from View. Returns None.<br>
bool = dvp.replaceCenterLine(cl)

# remove CenterLine cl from View. Returns None.
dvp.removeCenterLine(cl)
dvp.removeCenterLine(cl)


<!--T:69-->
CenterLine Attributes
CenterLine Attributes<br>
Tag: unique identifier. String. ReadOnly.
Type: 0 - face, 1 - 2 line, 2 - 2 point. Integer. ReadOnly.
Tag: unique identifier. String. ReadOnly.<br>
Mode: 0 - vert, 1 - horiz, 2 - aligned. Integer.
Type: 0 - face, 1 - 2 line, 2 - 2 point. Integer. ReadOnly.<br>
Mode: 0 - vert, 1 - horiz, 2 - aligned. Integer.<br>
Format: appearance attributes (style, color, weight, visible). Tuple.
Format: appearance attributes (style, color, weight, visible). Tuple.<br>
HorizShift: left/right offset. Float.
VertShift: up/down offset. Float.
HorizShift: left/right offset. Float.<br>
Rotation: rotation in degrees. Float.
VertShift: up/down offset. Float.<br>
Extension: additional length to be added. Float.
Rotation: rotation in degrees. Float.<br>
Extension: additional length to be added. Float.<br>
Flip: reverse the order of points for 2 point CenterLine. Boolean.
Flip: reverse the order of points for 2 point CenterLine. Boolean.<br>
Edges: names of source edges. List of string.
Faces: names of source faces. List of string.
Edges: names of source edges. List of string.<br>
Points: names of source points (Vertices). List of string.
Faces: names of source faces. List of string.<br>
Points: names of source points (Vertices). List of string.<br>


</translate>
<!--T:70-->
********************************************************************************
********************************************************************************
{{Code|code=

#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-


<!--T:71-->
# Py CenterLine demo
# Py CenterLine demo
import FreeCAD
import FreeCAD
Line 300: Line 346:
import TechDraw
import TechDraw


<!--T:72-->
start = FreeCAD.Vector (1.0, 5.0, 0.0) # middle, top
start = FreeCAD.Vector (1.0, 5.0, 0.0) # middle, top
end = FreeCAD.Vector(1.0, -5.0, 0.0) # middle, bottom
end = FreeCAD.Vector(1.0, -5.0, 0.0) # middle, bottom
Line 326: Line 373:
flip = False;
flip = False;


<!--T:73-->
dvp = App.ActiveDocument.View
dvp = App.ActiveDocument.View


<!--T:74-->
print("making face CenterLine")
print("making face CenterLine")
tag = dvp.makeCenterLine(faceNames,vMode)
tag = dvp.makeCenterLine(faceNames,vMode)
Line 333: Line 382:
print("cline tag: {}".format(tag))
print("cline tag: {}".format(tag))


<!--T:75-->
#replace
#replace
print("making new format")
print("making new format")
Line 340: Line 390:
cline.Extension = 10.0
cline.Extension = 10.0


<!--T:77-->
print("replacing CL with tag: {}".format(cline.Tag))
rc = dvp.replaceCenterLine(cline)
print("replace returns: {}".format(rc))

print("making edgeCenterLine")
print("making edgeCenterLine")
cline2 = dvp.makeCenterLine(edgeNames,hMode)
cline2 = dvp.makeCenterLine(edgeNames,hMode)


<!--T:78-->
print("making vertexCenterLine")
print("making vertexCenterLine")
cline3 = dvp.makeCenterLine(vertNames,aMode)
cline3 = dvp.makeCenterLine(vertNames,aMode)


<!--T:79-->
print("finished")
print("finished")
}}


<translate>
===DrawViewPart Geometry=== <!--T:16-->
===DrawViewPart Geometry=== <!--T:16-->

<!--T:87-->
[topoShapeEdge] = dvp.getVisibleEdges()
[topoShapeEdge] = dvp.getVisibleEdges()


Line 358: Line 411:
[topoShapeEdge] = dvp.getHiddenEdges()
[topoShapeEdge] = dvp.getHiddenEdges()


<!--T:80-->
topoShapeEdge = dvp.getEdgeByIndex(i) <br/>
topoShapeEdge = dvp.getEdgeBySelection("Edge1")


<!--T:6-->
<!--T:81-->
topoShapeVertex = dvp.getVertexByIndex(i) <br/>
{{TechDraw Tools navi}}
topoShapeVertex = dvp.getVertexBySelection("Vertex1")


<!--T:4-->
<!--T:82-->
Redraw the graphic for this View.<br>
[[Category:API]]
dvp.requestPaint()
[[Category:Poweruser Documentation]]


</translate>
</translate>
{{TechDraw Tools navi{{#translation:}}}}
{{Userdocnavi{{#translation:}}}}
[[Category:API{{#translation:}}]]
[[Category:Poweruser Documentation{{#translation:}}]]
{{clear}}
{{clear}}

Latest revision as of 10:15, 20 August 2023

(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

CosmeticVertex (CV) routines accessible from Python

dvp = App.ActiveDocument.View #CV's belong to views.

Add a CosmeticVertex at p1 (View coordinates). Returns unique tag.
tag = dvp.makeCosmeticVertex(vector p1)

Add a CosmeticVertex at p1 (3d model coordinates). Returns unique tag.
tag = dvp.makeCosmeticVertex3d(vector p1)

Returns CosmeticVertex with unique id.
cv = dvp.getCosmeticVertex(string id)

Returns CosmeticVertex with name (Vertex6). Used in selections.
cv = dvp.getCosmeticVertexBySelection(string name)

Removes CosmeticVertex from View. Returns None.
dvp.removeCosmeticVertex(object cv)

Removes all CosmeticVertices from the View. Returns None.
dvp.clearCosmeticVertices()

CosmeticView attributes
Tag: unique identifier. String.
Point: location within view. Vector.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Py CosmeticVertex demo
import FreeCAD
import TechDraw

v = App.ActiveDocument.View
p = App.Vector(-3.0, -3.0, 0.0)

#make CV
tag = v.makeCosmeticVertex(p)
print("t: {}".format(tag))

#retrieve CV
cv = v.getCosmeticVertex(tag)
print("cv: {}".format(cv))
print("Tag: {}".format(cv.Tag))


cv2 = v.getCosmeticVertexBySelection("Vertex4")
print("New Point: {}".format(cv2.Point))

#make CV from 3d
p3d = App.Vector(2.0, 2.0, 2.0)
print("3d point in: {}".format(p3d))
tag3d = v.makeCosmeticVertex3d(p3d)
cv3 = v.getCosmeticVertex(tag3d)
print("3d point out: {}".format(cv3.Point))

CosmeticEdge (CE) routines accessible from Python

dvp = App.ActiveDocument.View #CE's belong to views.

Make a CosmeticEdge from p1 to p2(View coordinates). Returns unique tag.
tag = dvp.makeCosmeticLine(p1, p2)

Make a CosmeticEdge at center with radius radius(View coordinates). Returns unique tag.
tag = dvp.makeCosmeticCircle(center, radius)

Make a CosmeticEdge at center with radius radius(View coordinates) from start angle to end angle. Returns unique tag.
tag = dvp.makeCosmeticCircleArc(center, radius, start, end)

Returns CosmeticEdge with unique id.
ce = dvp.getCosmeticEdge(id)

Returns CosmeticEdge by name (Edge25). Used in selections.
ce = dvp.getCosmeticEdgeBySelection(name)

Removes CosmeticEdge ce from View. Returns None.
dvp.removeCosmeticEdge(ce)

Removes all CosmeticLines from the View. Returns None.
dvp.clearCosmeticEdges()

CosmeticEdge attributes
Tag: unique identifier. String.
Format: appearance attributes (style, color, weight, visible). Tuple.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Py CosmeticEdge demo
import FreeCAD
import TechDraw

#points
org = App.Vector(0.0, 0.0, 0.0)
midTop = FreeCAD.Vector (1.0, 5.0, 0.0)   # middle, top
midBot = FreeCAD.Vector(2.0, -5.0, 0.0)      # middle, bottom
stdZ = FreeCAD.Vector(0.0, 0.0, 1.0)
center = FreeCAD.Vector(0.0, 0.0, 0.0)
arcCenter = FreeCAD.Vector(3.0, 3.0, 0.0)
vPt = FreeCAD.Vector(-3.0, 3.0, 0.0)
topRight = FreeCAD.Vector(5.0, 5.0, 0.0)
bottomLeft = FreeCAD.Vector(-5.0, -5.0, 0.0)

#angles
arcStart = -45
arcEnd = 45

#styles
solid = 1 
dashed = 2
dotted = 3
#weights
weight15 = 0.15
weight75 = 0.75
#colors
pyRed = (1.0, 0.0, 0.0, 0.0)
pyBlue = (0.0, 1.0, 0.0, 0.0)
pyGreen = (0.0, 0.0, 1.0, 0.0)
pyBlack = (0.0, 0.0, 0.0, 0.0)
shadow = (0.1, 0.1, 0.1, 0.0)

radius = 5.0
style = dashed
weight = weight75

dvp = App.ActiveDocument.View

print(dvp)

print("making line")
tag = dvp.makeCosmeticLine(midTop,midBot,style, weight, pyBlue)
ce = dvp.getCosmeticEdge(tag)
print("line tag: {}".format(tag))

print("making diagonal")
dvp.makeCosmeticLine(bottomLeft,topRight,solid, weight, pyGreen)

print("making circle")
tag2 = dvp.makeCosmeticCircle(center, radius, style, weight, pyRed)
ce2 = dvp.getCosmeticEdge(tag2)

print("making circleArc")
dvp.makeCosmeticCircleArc(arcCenter, radius, arcStart, arcEnd, style, weight, shadow)

#replace
print("making new format")
oldFormat = ce.Format
newFormat = (dotted,oldFormat[1], pyRed, True)
ce.Format = newFormat

print("removing CE with tag: {}".format(tag2))
dvp.removeCosmeticEdge(tag2)

print("finished")

CenterLine (CL) routines accessible from Python

Makes a new CenterLine
tag = dvp.makeCenterLine(subObjs, mode)

Retrieves CenterLine with unique tag.
cl = dvp.getCenterLine(tag)

Retrieves CenterLine by subobject name. Used in selection.
cl = dvp.getCenterLine("Edge5")

Removes CenterLine cl from View. Returns None.
dvp.removeCenterLine(cl)

CenterLine Attributes
Tag: unique identifier. String. ReadOnly.
Type: 0 - face, 1 - 2 line, 2 - 2 point. Integer. ReadOnly.
Mode: 0 - vert, 1 - horiz, 2 - aligned. Integer.
Format: appearance attributes (style, color, weight, visible). Tuple.
HorizShift: left/right offset. Float.
VertShift: up/down offset. Float.
Rotation: rotation in degrees. Float.
Extension: additional length to be added. Float.
Flip: reverse the order of points for 2 point CenterLine. Boolean.
Edges: names of source edges. List of string.
Faces: names of source faces. List of string.
Points: names of source points (Vertices). List of string.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Py CenterLine demo
import FreeCAD
import Part
import TechDraw

start = FreeCAD.Vector (1.0, 5.0, 0.0)   # middle, top
end = FreeCAD.Vector(1.0, -5.0, 0.0)      # middle, bottom
faceNames = ["Face0"]
edgeNames = ["Edge2", "Edge3"]
vertNames = ["Vertex1", "Vertex2"]
vMode = 0   #vertical
hMode = 1   #horizontal
aMode = 2   #aligned
#styles
solid = 1 
dashed = 2
dotted = 3
#weights
weight15 = 0.15
weight75 = 0.75
#colors
pyRed = (1.0, 0.0, 0.0, 0.0)
pyBlue = (0.0, 1.0, 0.0, 0.0)
pyBlack = (0.0, 0.0, 0.0, 0.0)
#adjustments
hShift = 1.0
vShift = 1.0
extend = 4.0
rotate = 30.0
flip = False;

dvp = App.ActiveDocument.View

print("making face CenterLine")
tag = dvp.makeCenterLine(faceNames,vMode)
cline = dvp.getCenterLine(tag)
print("cline tag: {}".format(tag))

#replace
print("making new format")
oldFormat = cline.Format
newFormat = (dotted,oldFormat[1], pyRed, True)
cline.Format = newFormat
cline.Extension = 10.0

print("making edgeCenterLine")
cline2 = dvp.makeCenterLine(edgeNames,hMode)

print("making vertexCenterLine")
cline3 = dvp.makeCenterLine(vertNames,aMode)

print("finished")

DrawViewPart Geometry

[topoShapeEdge] = dvp.getVisibleEdges()

[topoShapeEdge] = dvp.getHiddenEdges()

topoShapeEdge = dvp.getEdgeByIndex(i)
topoShapeEdge = dvp.getEdgeBySelection("Edge1")

topoShapeVertex = dvp.getVertexByIndex(i)
topoShapeVertex = dvp.getVertexBySelection("Vertex1")

Redraw the graphic for this View.
dvp.requestPaint()