FreeCAD Python
Modules | Namespaces | Functions
DRAFT

Detailed Description

Create and manipulate basic 2D objects.

This module offers a range of tools to create and manipulate basic 2D objects

The module allows to create 2D geometric objects such as line, rectangle, circle, etc, modify these objects by moving, scaling or rotating them, and offers a couple of other utilities to manipulate further these objects, such as decompose them (downgrade) into smaller elements.

The functionality of the module is divided into GUI tools, usable from the FreeCAD interface, and corresponding python functions, that can perform the same operation programmatically.

Modules

 DraftGeomUtils
 Shape manipulation utilities for the Draft workbench.
 
 DraftVecUtils
 Vector math utilities used in Draft workbench.
 

Namespaces

 DraftGui
 GUI elements and utilities of the Draft workbench.
 
 DraftSnap
 Snapping system used by Draft & Arch workbenches.
 
 DraftTools
 GUI Commands of the Draft workbench.
 
 DraftTrackers
 Custom Pivy-based objects used by the Draft workbench.
 
 importAirfoilDAT
 Airfoil (.dat) file importer.
 
 importDWG
 DWG file importer & exporter.
 
 importDXF
 DXF file importer & exporter.
 
 importOCA
 OCA (Open CAD Format) file import & export.
 
 importSVG
 SVG file importer & exporter.
 
 WorkingPlane
 This module handles the Working Plane and grid of the Draft module.
 

Functions

def Draft.stringencodecoin (ustr)
 
def Draft.epsilon ()
 
def Draft.getObjectsOfType (objectslist, typ)
 
def Draft.isClone (obj, objtype, recursive=False)
 
def Draft.dimDash (p1, p2)
 
def Draft.shapify (obj)
 
def Draft.getGroupContents (objectslist, walls=False, addgroups=False, spaces=False, noarchchild=False)
 
def Draft.removeHidden (objectslist)
 
def Draft.printShape (shape)
 
def Draft.formatObject (target, origin=None)
 
def Draft.svgpatterns ()
 
def Draft.loadTexture (filename, size=None)
 
def Draft.getMovableChildren (objectslist, recursive=True)
 
def Draft.makeCircle (radius, placement=None, face=None, startangle=None, endangle=None, support=None)
 
def Draft.makeRectangle (length, height, placement=None, face=None, support=None)
 
def Draft.makeDimension (p1, p2, p3=None, p4=None)
 
def Draft.makeAngularDimension (center, angles, p3, normal=None)
 
def Draft.makeWire (pointslist, closed=False, placement=None, face=None, support=None)
 
def Draft.makePolygon (nfaces, radius=1, inscribed=True, placement=None, face=None, support=None)
 
def Draft.makeLine (p1, p2=None)
 
def Draft.makeBSpline (pointslist, closed=False, placement=None, face=None, support=None)
 
def Draft.makeBezCurve (pointslist, closed=False, placement=None, face=None, support=None, Degree=None)
 
def Draft.makeText (stringslist, point=Vector(0, 0, 0), screen=False)
 
def Draft.makeCopy (obj, force=None, reparent=False)
 
def Draft.makeBlock (objectslist)
 
def Draft.makeArray (baseobject, arg1, arg2, arg3, arg4=None, arg5=None, arg6=None, name="Array")
 
def Draft.makePathArray (baseobject, pathobject, count, xlate=None, align=False, pathobjsubs=[])
 
def Draft.makePointArray (base, ptlst)
 
def Draft.makeEllipse (majradius, minradius, placement=None, face=True, support=None)
 
def Draft.extrude (obj, vector, solid=False)
 
def Draft.joinWires (wires, joinAttempts=0)
 
def Draft.joinTwoWires (wire1, wire2)
 
def Draft.fuse (object1, object2)
 
def Draft.move (objectslist, vector, copy=False)
 
def Draft.array (objectslist, arg1, arg2, arg3, arg4=None, arg5=None, arg6=None)
 
def Draft.rotate (objectslist, angle, center=Vector(0, 0, 0), axis=Vector(0, 0, 1), copy=False)
 
def Draft.scale (objectslist, scale=Vector(1, 1, 1), center=Vector(0, 0, 0), copy=False)
 
def Draft.offset (obj, delta, copy=False, bind=False, sym=False, occ=False)
 
def Draft.draftify (objectslist, makeblock=False, delete=True)
 
def Draft.getDXF (obj, direction=None)
 
def Draft.getrgb (color, testbw=True)
 
def Draft.makeDrawingView (obj, page, lwmod=None, tmod=None, otherProjection=None)
 
def Draft.makeShape2DView (baseobj, projectionVector=None, facenumbers=[])
 
def Draft.makeSketch (objectslist, autoconstraints=False, addTo=None, delete=False, name="Sketch", radiusPrecision=-1)
 
def Draft.makePoint (X=0, Y=0, Z=0, color=None, name="Point", point_size=5)
 
def Draft.makeShapeString (String, FontFile, Size=100, Tracking=0)
 
def Draft.clone (obj, delta=None, forcedraft=False)
 
def Draft.getCloneBase (obj, strict=False)
 
def Draft.mirror (objlist, p1, p2)
 
def Draft.heal (objlist=None, delete=True, reparent=True)
 
def Draft.makeFacebinder (selectionset, name="Facebinder")
 
def Draft.upgrade (objects, delete=False, force=None)
 
def Draft.downgrade (objects, delete=False, force=None)
 
def Draft.getParameterFromV0 (edge, offset)
 
def Draft.calculatePlacement (globalRotation, edge, offset, RefPt, xlate, align, normal=None)
 
def Draft.calculatePlacementsOnPath (shapeRotation, pathwire, count, xlate, align)
 

Function Documentation

◆ array()

def Draft.array (   objectslist,
  arg1,
  arg2,
  arg3,
  arg4 = None,
  arg5 = None,
  arg6 = None 
)
array(objectslist,xvector,yvector,xnum,ynum) for rectangular array,
array(objectslist,xvector,yvector,zvector,xnum,ynum,znum) for rectangular array,
or array(objectslist,center,totalangle,totalnum) for polar array: Creates an array
of the objects contained in list (that can be an object or a list of objects)
with, in case of rectangular array, xnum of iterations in the x direction
at xvector distance between iterations, and same for y and z directions with yvector
and ynum and zvector and znum. In case of polar array, center is a vector, totalangle
is the angle to cover (in degrees) and totalnum is the number of objects, including
the original.

This function creates an array of independent objects. Use makeArray() to create a
parametric array object.

◆ calculatePlacement()

def Draft.calculatePlacement (   globalRotation,
  edge,
  offset,
  RefPt,
  xlate,
  align,
  normal = None 
)
Orient shape to tangent at parm offset along edge.

◆ calculatePlacementsOnPath()

def Draft.calculatePlacementsOnPath (   shapeRotation,
  pathwire,
  count,
  xlate,
  align 
)
Calculates the placements of a shape along a given path so that each copy will be distributed evenly

◆ clone()

def Draft.clone (   obj,
  delta = None,
  forcedraft = False 
)
clone(obj,[delta,forcedraft]): makes a clone of the given object(s). The clone is an exact,
linked copy of the given object. If the original object changes, the final object
changes too. Optionally, you can give a delta Vector to move the clone from the
original position. If forcedraft is True, the resulting object is a Draft clone
even if the input object is an Arch object.

◆ dimDash()

def Draft.dimDash (   p1,
  p2 
)
dimDash(p1, p2): returns pivy SoSeparator.
Used for making Tick-2, DimOvershoot, ExtOvershoot dashes.

◆ downgrade()

def Draft.downgrade (   objects,
  delete = False,
  force = None 
)
downgrade(objects,delete=False,force=None): Downgrades the given object(s) (can be
an object or a list of objects). If delete is True, old objects are deleted.
The force attribute can be used to
force a certain way of downgrading. It can be: explode, shapify, subtr,
splitFaces, cut2, getWire, splitWires, splitCompounds.
Returns a dictionary containing two lists, a list of new objects and a list
of objects to be deleted

◆ draftify()

def Draft.draftify (   objectslist,
  makeblock = False,
  delete = True 
)
draftify(objectslist,[makeblock],[delete]): turns each object of the given list
(objectslist can also be a single object) into a Draft parametric
wire. If makeblock is True, multiple objects will be grouped in a block.
If delete = False, old objects are not deleted

◆ epsilon()

def Draft.epsilon ( )
epsilon(): returns a small number based on Draft.tolerance() for use in
floating point comparisons.  Use with caution. 

◆ extrude()

def Draft.extrude (   obj,
  vector,
  solid = False 
)
makeExtrusion(object,vector): extrudes the given object
in the direction given by the vector. The original object
gets hidden.

◆ formatObject()

def Draft.formatObject (   target,
  origin = None 
)
formatObject(targetObject,[originObject]): This function applies
to the given target object the current properties
set on the toolbar (line color and line width),
or copies the properties of another object if given as origin.
It also places the object in construction group if needed.

◆ fuse()

def Draft.fuse (   object1,
  object2 
)
fuse(oject1,object2): returns an object made from
the union of the 2 given objects. If the objects are
coplanar, a special Draft Wire is used, otherwise we use
a standard Part fuse.

◆ getCloneBase()

def Draft.getCloneBase (   obj,
  strict = False 
)
getCloneBase(obj,[strict]): returns the object cloned by this object, if
any, or this object if it is no clone. If strict is True, if this object is
not a clone, this function returns False

◆ getDXF()

def Draft.getDXF (   obj,
  direction = None 
)
getDXF(object,[direction]): returns a DXF entity from the given
object. If direction is given, the object is projected in 2D.

◆ getGroupContents()

def Draft.getGroupContents (   objectslist,
  walls = False,
  addgroups = False,
  spaces = False,
  noarchchild = False 
)
getGroupContents(objectlist,[walls,addgroups]): if any object of the given list
is a group, its content is appended to the list, which is returned. If walls is True,
walls and structures are also scanned for included windows or rebars. If addgroups
is true, the group itself is also included in the list.

◆ getMovableChildren()

def Draft.getMovableChildren (   objectslist,
  recursive = True 
)
getMovableChildren(objectslist,[recursive]): extends the given list of objects
with all child objects that have a "MoveWithHost" property set to True. If
recursive is True, all descendents are considered, otherwise only direct children.

◆ getObjectsOfType()

def Draft.getObjectsOfType (   objectslist,
  typ 
)
getObjectsOfType(objectslist,typ): returns a list of objects of type "typ" found
in the given object list

◆ getParameterFromV0()

def Draft.getParameterFromV0 (   edge,
  offset 
)
return parameter at distance offset from edge.Vertexes[0]
sb method in Part.TopoShapeEdge???

◆ getrgb()

def Draft.getrgb (   color,
  testbw = True 
)
getRGB(color,[testbw]): returns a rgb value #000000 from a freecad color
if testwb = True (default), pure white will be converted into pure black

◆ heal()

def Draft.heal (   objlist = None,
  delete = True,
  reparent = True 
)
heal([objlist],[delete],[reparent]) - recreates Draft objects that are damaged,
for example if created from an earlier version. If delete is True,
the damaged objects are deleted (default). If ran without arguments, all the objects
in the document will be healed if they are damaged. If reparent is True (default),
new objects go at the very same place in the tree than their original.

◆ isClone()

def Draft.isClone (   obj,
  objtype,
  recursive = False 
)
isClone(obj,objtype,[recursive]): returns True if the given object is
a clone of an object of the given type. If recursive is True, also check if
the clone is a clone of clone (of clone...)  of the given type.

◆ joinTwoWires()

def Draft.joinTwoWires (   wire1,
  wire2 
)
joinTwoWires(object, object): joins two wires if they share a common
point as a start or an end

◆ joinWires()

def Draft.joinWires (   wires,
  joinAttempts = 0 
)
joinWires(objects): merges a set of wires where possible, if any of those
wires have a coincident start and end point

◆ loadTexture()

def Draft.loadTexture (   filename,
  size = None 
)
loadTexture(filename,[size]): returns a SoSFImage from a file. If size
is defined (an int or a tuple), and provided the input image is a png file,
it will be scaled to match the given size.

◆ makeAngularDimension()

def Draft.makeAngularDimension (   center,
  angles,
  p3,
  normal = None 
)
makeAngularDimension(center,angle1,angle2,p3,[normal]): creates an angular Dimension
from the given center, with the given list of angles, passing through p3.

◆ makeArray()

def Draft.makeArray (   baseobject,
  arg1,
  arg2,
  arg3,
  arg4 = None,
  arg5 = None,
  arg6 = None,
  name = "Array" 
)
makeArray(object,xvector,yvector,xnum,ynum,[name]) for rectangular array, or
makeArray(object,xvector,yvector,zvector,xnum,ynum,znum,[name]) for rectangular array, or
makeArray(object,center,totalangle,totalnum,[name]) for polar array: Creates an array
of the given object
with, in case of rectangular array, xnum of iterations in the x direction
at xvector distance between iterations, same for y direction with yvector and ynum,
same for z direction with zvector and znum. In case of polar array, center is a vector,
totalangle is the angle to cover (in degrees) and totalnum is the number of objects,
including the original. The result is a parametric Draft Array.

◆ makeBezCurve()

def Draft.makeBezCurve (   pointslist,
  closed = False,
  placement = None,
  face = None,
  support = None,
  Degree = None 
)
makeBezCurve(pointslist,[closed],[placement]): Creates a Bezier Curve object
from the given list of vectors.   Instead of a pointslist, you can also pass a Part Wire.

◆ makeBlock()

def Draft.makeBlock (   objectslist)
makeBlock(objectslist): Creates a Draft Block from the given objects

◆ makeBSpline()

def Draft.makeBSpline (   pointslist,
  closed = False,
  placement = None,
  face = None,
  support = None 
)
makeBSpline(pointslist,[closed],[placement]): Creates a B-Spline object
from the given list of vectors. If closed is True or first
and last points are identical, the wire is closed. If face is
true (and wire is closed), the wire will appear filled. Instead of
a pointslist, you can also pass a Part Wire.

◆ makeCircle()

def Draft.makeCircle (   radius,
  placement = None,
  face = None,
  startangle = None,
  endangle = None,
  support = None 
)
makeCircle(radius,[placement,face,startangle,endangle])
or makeCircle(edge,[face]):
Creates a circle object with given radius. If placement is given, it is
used. If face is False, the circle is shown as a
wireframe, otherwise as a face. If startangle AND endangle are given
(in degrees), they are used and the object appears as an arc. If an edge
is passed, its Curve must be a Part.Circle

◆ makeCopy()

def Draft.makeCopy (   obj,
  force = None,
  reparent = False 
)
makeCopy(object): returns an exact copy of an object

◆ makeDimension()

def Draft.makeDimension (   p1,
  p2,
  p3 = None,
  p4 = None 
)
makeDimension(p1,p2,[p3]) or makeDimension(object,i1,i2,p3)
or makeDimension(objlist,indices,p3): Creates a Dimension object with
the dimension line passign through p3.The current line width and color
will be used. There are multiple  ways to create a dimension, depending on
the arguments you pass to it:
- (p1,p2,p3): creates a standard dimension from p1 to p2
- (object,i1,i2,p3): creates a linked dimension to the given object,
measuring the distance between its vertices indexed i1 and i2
- (object,i1,mode,p3): creates a linked dimension
to the given object, i1 is the index of the (curved) edge to measure,
and mode is either "radius" or "diameter".

◆ makeDrawingView()

def Draft.makeDrawingView (   obj,
  page,
  lwmod = None,
  tmod = None,
  otherProjection = None 
)
makeDrawingView(object,page,[lwmod,tmod]) - adds a View of the given object to the
given page. lwmod modifies lineweights (in percent), tmod modifies text heights
(in percent). The Hint scale, X and Y of the page are used.

◆ makeEllipse()

def Draft.makeEllipse (   majradius,
  minradius,
  placement = None,
  face = True,
  support = None 
)
makeEllipse(majradius,minradius,[placement],[face],[support]): makes
an ellipse with the given major and minor radius, and optionally
a placement.

◆ makeFacebinder()

def Draft.makeFacebinder (   selectionset,
  name = "Facebinder" 
)
makeFacebinder(selectionset,[name]): creates a Facebinder object from a selection set.
Only faces will be added.

◆ makeLine()

def Draft.makeLine (   p1,
  p2 = None 
)
makeLine(p1,p2): Creates a line between p1 and p2.
makeLine(LineSegment): Creates a line from a Part.LineSegment
makeLine(Shape): Creates a line from first vertex to last vertex of the given shape

◆ makePathArray()

def Draft.makePathArray (   baseobject,
  pathobject,
  count,
  xlate = None,
  align = False,
  pathobjsubs = [] 
)
makePathArray(docobj,path,count,xlate,align,pathobjsubs): distribute
count copies of a document baseobject along a pathobject or subobjects of a
pathobject. Optionally translates each copy by FreeCAD.Vector xlate direction
and distance to adjust for difference in shape centre vs shape reference point.
Optionally aligns baseobject to tangent/normal/binormal of path.

◆ makePoint()

def Draft.makePoint (   X = 0,
  Y = 0,
  Z = 0,
  color = None,
  name = "Point",
  point_size = 5 
)
makePoint(x,y,z ,[color(r,g,b),point_size]) or
    makePoint(Vector,color(r,g,b),point_size]) -
    creates a Point in the current document.
    example usage:
    p1 = makePoint()
    p1.ViewObject.Visibility= False # make it invisible
    p1.ViewObject.Visibility= True  # make it visible
    p1 = makePoint(-1,0,0) #make a point at -1,0,0
    p1 = makePoint(1,0,0,(1,0,0)) # color = red
    p1.X = 1 #move it in x
    p1.ViewObject.PointColor =(0.0,0.0,1.0) #change the color-make sure values are floats

◆ makePointArray()

def Draft.makePointArray (   base,
  ptlst 
)
makePointArray(base,pointlist):

◆ makePolygon()

def Draft.makePolygon (   nfaces,
  radius = 1,
  inscribed = True,
  placement = None,
  face = None,
  support = None 
)
makePolgon(nfaces,[radius],[inscribed],[placement],[face]): Creates a
polygon object with the given number of faces and the radius.
if inscribed is False, the polygon is circumscribed around a circle
with the given radius, otherwise it is inscribed. If face is True,
the resulting shape is displayed as a face, otherwise as a wireframe.

◆ makeRectangle()

def Draft.makeRectangle (   length,
  height,
  placement = None,
  face = None,
  support = None 
)
makeRectangle(length,width,[placement],[face]): Creates a Rectangle
object with length in X direction and height in Y direction.
If a placement is given, it is used. If face is False, the
rectangle is shown as a wireframe, otherwise as a face.

◆ makeShape2DView()

def Draft.makeShape2DView (   baseobj,
  projectionVector = None,
  facenumbers = [] 
)
makeShape2DView(object,[projectionVector,facenumbers]) - adds a 2D shape to the document, which is a
2D projection of the given object. A specific projection vector can also be given. You can also
specify a list of face numbers to be considered in individual faces mode.

◆ makeShapeString()

def Draft.makeShapeString (   String,
  FontFile,
  Size = 100,
  Tracking = 0 
)
ShapeString(Text,FontFile,Height,Track): Turns a text string
into a Compound Shape

◆ makeSketch()

def Draft.makeSketch (   objectslist,
  autoconstraints = False,
  addTo = None,
  delete = False,
  name = "Sketch",
  radiusPrecision = -1 
)
makeSketch(objectslist,[autoconstraints],[addTo],[delete],[name],[radiusPrecision]):

Makes a Sketch objectslist with the given Draft objects.

* objectlist: can be single or list of objects of Draft type objects,
    Part::Feature, Part.Shape, or mix of them.

* autoconstraints(False): if True, constraints will be automatically added to
    wire nodes, rectangles and circles.

* addTo(None) : if set to an existing sketch, geometry will be added to it
    instead of creating a new one.

* delete(False): if True, the original object will be deleted.
    If set to a string 'all' the object and all its linked object will be
    deleted

* name('Sketch'): the name for the new sketch object

* radiusPrecision(-1): If <0, disable radius constraint. If =0, add indiviaul
    radius constraint. If >0, the radius will be rounded according to this
    precision, and 'Equal' constraint will be added to curve with equal
    radius within precision.

◆ makeText()

def Draft.makeText (   stringslist,
  point = Vector(0,0,0),
  screen = False 
)
makeText(strings,[point],[screen]): Creates a Text object at the given point,
containing the strings given in the strings list, one string by line (strings
can also be one single string). The current color and text height and font
specified in preferences are used.
If screen is True, the text always faces the view direction.

◆ makeWire()

def Draft.makeWire (   pointslist,
  closed = False,
  placement = None,
  face = None,
  support = None 
)
makeWire(pointslist,[closed],[placement]): Creates a Wire object
from the given list of vectors. If closed is True or first
and last points are identical, the wire is closed. If face is
true (and wire is closed), the wire will appear filled. Instead of
a pointslist, you can also pass a Part Wire.

◆ mirror()

def Draft.mirror (   objlist,
  p1,
  p2 
)
mirror(objlist,p1,p2,[clone]): creates a mirrored version of the given object(s)
along an axis that passes through the two vectors p1 and p2.

◆ move()

def Draft.move (   objectslist,
  vector,
  copy = False 
)
move(objects,vector,[copy]): Moves the objects contained
in objects (that can be an object or a list of objects)
in the direction and distance indicated by the given
vector. If copy is True, the actual objects are not moved, but copies
are created instead. The objects (or their copies) are returned.

◆ offset()

def Draft.offset (   obj,
  delta,
  copy = False,
  bind = False,
  sym = False,
  occ = False 
)
offset(object,delta,[copymode],[bind]): offsets the given wire by
applying the given delta Vector to its first vertex. If copymode is
True, another object is created, otherwise the same object gets
offsetted. If bind is True, and provided the wire is open, the original
and the offsetted wires will be bound by their endpoints, forming a face
if sym is True, bind must be true too, and the offset is made on both
sides, the total width being the given delta length. If offsetting a
BSpline, the delta must not be a Vector but a list of Vectors, one for
each node of the spline.

◆ printShape()

def Draft.printShape (   shape)
prints detailed information of a shape

◆ removeHidden()

def Draft.removeHidden (   objectslist)
removeHidden(objectslist): removes hidden objects from the list

◆ rotate()

def Draft.rotate (   objectslist,
  angle,
  center = Vector(0,0,0),
  axis = Vector(0,0,1),
  copy = False 
)
rotate(objects,angle,[center,axis,copy]): Rotates the objects contained
in objects (that can be a list of objects or an object) of the given angle
(in degrees) around the center, using axis as a rotation axis. If axis is
omitted, the rotation will be around the vertical Z axis.
If copy is True, the actual objects are not moved, but copies
are created instead. The objects (or their copies) are returned.

◆ scale()

def Draft.scale (   objectslist,
  scale = Vector(1,1,1),
  center = Vector(0,0,0),
  copy = False 
)
scale(objects,vector,[center,copy,legacy]): Scales the objects contained
in objects (that can be a list of objects or an object) of the given scale
factors defined by the given vector (in X, Y and Z directions) around
given center. If copy is True, the actual objects are not moved, but copies
are created instead. The objects (or their copies) are returned.

◆ shapify()

def Draft.shapify (   obj)
shapify(object): transforms a parametric shape object into
non-parametric and returns the new object

◆ stringencodecoin()

def Draft.stringencodecoin (   ustr)
stringencodecoin(str): Encodes a unicode object to be used as a string in coin

◆ svgpatterns()

def Draft.svgpatterns ( )
svgpatterns(): returns a dictionary with installed SVG patterns

◆ upgrade()

def Draft.upgrade (   objects,
  delete = False,
  force = None 
)
upgrade(objects,delete=False,force=None): Upgrades the given object(s) (can be
an object or a list of objects). If delete is True, old objects are deleted.
The force attribute can be used to
force a certain way of upgrading. It can be: makeCompound, closeGroupWires,
makeSolid, closeWire, turnToParts, makeFusion, makeShell, makeFaces, draftify,
joinFaces, makeSketchFace, makeWires
Returns a dictionary containing two lists, a list of new objects and a list
of objects to be deleted