Draft API: Difference between revisions

From FreeCAD Documentation
(Created page with 'These functions are part of the Draft module and can be used in scripts and macros or from the python interpreter, once the Draft module has been imported: from Draft import * …')
 
No edit summary
Line 4: Line 4:
* '''makeCircle'''(radius,[placement,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. The current line width and color will be used. Example:
* '''makeCircle'''(radius,[placement,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. The current line width and color will be used. Example:
makeCircle(2)
makeCircle(2)

* '''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. The current line width and color will be used. Example:
* '''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. The current line width and color will be used. Example:
makeRectangle(3,4)
makeRectangle(3,4)

* '''makeDimension'''(p1,p2,[p3]) - Creates a Dimension object measuring distance between p1 and p2, optionally with the dimension line passing through p3. The current line width and color will be used. Example:
* '''makeDimension'''(p1,p2,[p3]) - Creates a Dimension object measuring distance between p1 and p2, optionally with the dimension line passing through p3. The current line width and color will be used. Example:
p1 = FreeCAD.Vector(0,0,0)
p1 = FreeCAD.Vector(0,0,0)
p2 = FreeCAD.Vector(2,0,0)
p2 = FreeCAD.Vector(2,0,0)
makeDimension(p1,p2)
makeDimension(p1,p2)

* '''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. The current line width and color will be used. If only 2 points are given, the closed value is disregarded, and a simple 2-point line is created. Example:
* '''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. The current line width and color will be used. If only 2 points are given, the closed value is disregarded, and a simple 2-point line is created. Example:
p1 = FreeCAD.Vector(0,0,0)
p1 = FreeCAD.Vector(0,0,0)
p2 = FreeCAD.Vector(2,0,0)
p2 = FreeCAD.Vector(2,0,0)
makeWire([p1,p2])
makeWire([p1,p2])

* '''makeLine'''(p1,p2): Creates a line between p1 and p2. This is a simpler version of the makeWire function for 2-points lines only.
* '''makeLine'''(p1,p2): Creates a line between p1 and p2. This is a simpler version of the makeWire function for 2-points lines only.

* '''makeText'''(point,stringslist,[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. Example:
makeText(FreeCAD.Vector(0,0,0),"Hello, World!")

* '''move'''(objectslist,vector,[copy]) - Moves the objects contained in objectslist 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 given objectslist can be either a list of objects or a single object. Example:
* '''move'''(objectslist,vector,[copy]) - Moves the objects contained in objectslist 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 given objectslist can be either a list of objects or a single object. Example:
p1 = FreeCAD.Vector(0,0,0)
p1 = FreeCAD.Vector(0,0,0)
Line 21: Line 29:
delta = FreeCAD.Vector(2,2,0)
delta = FreeCAD.Vector(2,2,0)
move(obj,delta)
move(obj,delta)

* '''rotate'''(objects,angle,center,[axis,copy]): Rotates the objects contained in objects (that can be a list of objects or a single object) applying the given angle (given in radians) around the center, using axis as a rotation axis. If axis is omitted, the rotation will be around the vertical Z axis (0,0,1). If copy is True, the actual objects are not moved, but copies are created instead. The objects (or their copies) are returned. Example:
p1 = FreeCAD.Vector(0,0,0)
obj = makeWire([p1,p2])
rotate(obj,1.59,p1)

Revision as of 23:41, 12 July 2010

These functions are part of the Draft module and can be used in scripts and macros or from the python interpreter, once the Draft module has been imported:

from Draft import *
  • makeCircle(radius,[placement,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. The current line width and color will be used. Example:
makeCircle(2)
  • 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. The current line width and color will be used. Example:
makeRectangle(3,4)
  • makeDimension(p1,p2,[p3]) - Creates a Dimension object measuring distance between p1 and p2, optionally with the dimension line passing through p3. The current line width and color will be used. Example:
p1 = FreeCAD.Vector(0,0,0)
p2 = FreeCAD.Vector(2,0,0)
makeDimension(p1,p2)
  • 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. The current line width and color will be used. If only 2 points are given, the closed value is disregarded, and a simple 2-point line is created. Example:
p1 = FreeCAD.Vector(0,0,0)
p2 = FreeCAD.Vector(2,0,0)
makeWire([p1,p2])
  • makeLine(p1,p2): Creates a line between p1 and p2. This is a simpler version of the makeWire function for 2-points lines only.
  • makeText(point,stringslist,[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. Example:
makeText(FreeCAD.Vector(0,0,0),"Hello, World!")
  • move(objectslist,vector,[copy]) - Moves the objects contained in objectslist 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 given objectslist can be either a list of objects or a single object. Example:
p1 = FreeCAD.Vector(0,0,0)
p2 = FreeCAD.Vector(2,0,0)
obj = makeWire([p1,p2])
delta = FreeCAD.Vector(2,2,0)
move(obj,delta)
  • rotate(objects,angle,center,[axis,copy]): Rotates the objects contained in objects (that can be a list of objects or a single object) applying the given angle (given in radians) around the center, using axis as a rotation axis. If axis is omitted, the rotation will be around the vertical Z axis (0,0,1). If copy is True, the actual objects are not moved, but copies are created instead. The objects (or their copies) are returned. Example:
p1 = FreeCAD.Vector(0,0,0)
obj = makeWire([p1,p2])
rotate(obj,1.59,p1)