TechDraw API

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

Example:

Example:

Example:

Example:

CosmeticVertex (CV) routines accessible from Python

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

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

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

cv = dvp.getCosmeticVertex(string id)
 * 1) returns CosmeticVertex with unique id.

cv = dvp.getCosmeticVertexBySelection(string name)
 * 1) returns CosmeticVertex with name (Vertex6).  Used in selections.

bool = dvp.replaceCosmeticVertex(object cv)
 * 1) replaces CosmeticVertex in View. Returns True/False.

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

dvp.clearCosmeticVertices
 * 1) remove all CosmeticVertices from the View. Returns None.

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




 * 1) !/usr/bin/env python
 * 2) -*- coding: utf-8 -*-

import FreeCAD import TechDraw
 * 1) Py CosmeticVertex demo

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

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

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

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

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

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))
 * 1) make CV from 3d

CosmeticEdge (CE) routines accessible from Python

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

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

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

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

ce = dvp.getCosmeticEdge(id)
 * 1) returns CosmeticEdge with unique id.

ce = dvp.getCosmeticEdgeBySelection(name)
 * 1) returns CosmeticEdge by name (Edge25).  Used in selections

bool = dvp.replaceCosmeticEdge(ce)
 * 1) replace CosmeticEdge ce in dvp PropertyCosmeticEdgeList. ce.Tag must match an existing tag

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

dvp.clearCosmeticEdges
 * 1) remove all CosmeticLines from the View. Returns None.

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




 * 1) !/usr/bin/env python
 * 2) -*- coding: utf-8 -*-

import FreeCAD import TechDraw
 * 1) Py CosmeticEdge demo

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)
 * 1) points

arcStart = -45 arcEnd = 45
 * 1) angles

solid = 1 dashed = 2 dotted = 3 weight15 = 0.15 weight75 = 0.75 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)
 * 1) styles
 * 1) weights
 * 1) colors

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)

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

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)) dvp.removeCosmeticEdge(tag2)

print("finished")

CenterLine (CL) routines accessible from Python
tag = dvp.makeCenterLine(subObjs, mode)
 * 1) make a new CenterLine

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

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

bool = dvp.replaceCenterLine(cl)
 * 1) replace CenterLine cl in dvp PropertyCenterLineList. cl.Tag must match an existing tag

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

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.




 * 1) !/usr/bin/env python
 * 2) -*- coding: utf-8 -*-

import FreeCAD import Part import TechDraw
 * 1) Py CenterLine demo

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 solid = 1 dashed = 2 dotted = 3 weight15 = 0.15 weight75 = 0.75 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) hShift = 1.0 vShift = 1.0 extend = 4.0 rotate = 30.0 flip = False;
 * 1) styles
 * 1) weights
 * 1) colors
 * 1) adjustments

dvp = App.ActiveDocument.View

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

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

print("replacing CL with tag: {}".format(cline.Tag)) rc = dvp.replaceCenterLine(cline) print("replace returns: {}".format(rc))

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