Builtin modules
This page presents more in-depth information over the built-in FreeCAD modules, and what are the functions and properties availible to you. This page is not a complete list of all the contents of these modules, and, because of the fast evolution of FreeCAD, the information presented here might be slightly outdated, but it should give you a good overview of the possibilities. For complete list of the modules content, use the dir(module) function in the interpreter.
The FreeCAD module
This is the principal (root) module of FreeCAD. It can also be called by "App" from the FreeCAD interpreter. It contains everything that is needed to manipulate documents and their contents (objects).
Example:
import FreeCAD print FreeCAD.listDocuments() mydoc = FreeCAD.activeDocument()
Description: Prints a dictionnnary containing all the FreeCAD configuration environment.
Returns:
Description: Returns the value of the given key. If no key is given, the complete configuration is returned
Returns: A string.
Description: Set the given key (first string) to the given value (second string).
Returns:
Description:
Returns: Return the active document or None if there is no active document.
Description: Adds a new export file type to FreeCAD. The first string must be formatted like this example: "Word Document (*.doc)". The second string is the name of a python script/module containing an export() function.
Returns:
Description: Adds a new import file type to FreeCAD, works the same way as addExportType, the handling python module must contain an open() and/or an import() function.
Returns:
Description: Returns a document or raise an exception if there is no document with the given name.
Returns:
Description: Returns the name of the module that can export the specified filetype.
Returns: A string.
Description: Returns the name of the module that can import the specified filetype.
Returns: A string.
Description: Creates and returns a new document with a given name. The document name must be unique, which is checked automatically. If no name is supplied, the document will be named "Untitled".
Returns: The newly created document.
Description: Creates and returns a document and load a project file into the document. The string argument must point to an existing file. If the file doesn't exist or the file cannot be loaded an I/O exception is thrown. In this case the created document is kept, but will be empty.
Returns: The opened FreeCAD Document.
Base
The Base module is contained inside the FreeCAD module and contains constructors for different types of objects heavily used in FreeCAD.
Description: Creates a bounding box. A bounding box is an orthographic cube which is a way to describe outer boundaries. You get a bounding box from a lot of 3D types. It is often used to check if a 3D entity lies in the range of another object. Checking for boundig interference first can save a lot of computing time!
Vectors
Vectors are used everywhere in FreeCAD.
Example:
v=FreeCAD.Vector() v=FreeCAD.Vector(1,0,0) v=FreeCAD.Base.Vector() v2 = FreeCAD.Vector(3,2,-5) v3 = v.add(v2) print v3.Length
Description:
Returns: the distance between the vector and a line between Vector1 and Vector2.
Description:
Returns: the distance between the vector and a plane defined by a point and a normal.
Description: projects the vector on a line between Vector1 and Vector2.
Returns: nothing.
Description: projects the vector on a plane defined by a point and a normal.
Returns: nothing.
Description: Same as multiply but lets specify different values for x, y and z directions.
Returns: nothing.
Description: subtracts another vector from the first one.
Returns: the resulting vector.
Matrixes
4x4 Matrixes are used everywhere throughout FreeCAD and can be created by one of the following manners:
m=FreeCAD.Matrix() m=FreeCAD.Base.Matrix() print m.A21()
Description: Computes the determinant of the matrix
Returns: the matrix determinant.
Description: Multiplies a matrix or vector with this matrix
Returns: nothing.
Console module
This module is contained inside the FreeCAD module and contains methods to send text to FreeCAD's output console and status bar. The messages will have different color if they are message, warning or error. Example:
import FreeCAD FreeCAD.PrintMessage("Hello World!\n")
Description: Get the status for either Log, Msg, Wrn or Error for an observer
Returns: a status string.
Description: Set the stats for either Log, Msg, Wrn or Error for an observer
Returns:
The FreeCADGui Module
This module is the counterpart of the FreeCAD module. It contains everything related to the User interface and the 3D views. Example:
import FreeCADGui doc = FreeCADGui.activeDocument()
Description: Adds a FreeCAD command. String is the name of the command and object is a classname defining the command
Returns:
Description: Adds an icon as file name or in XPM format to the system
Returns:
Description: Adds a UI form to the preferences dialog. The first argument specifies the file name and the second specifies the group name
Returns:
Description: Adds a workbench under a defined name. The string is the workbench name and the object is a classname defining the workbench
Returns:
Selection module
The selection submodule is part of the FreeCADGui module. Example:
import FreeCADGui sel = FreeCADGui.Selection.getSelection()
Description: Clears the selection of the given document name. If no document is given the complete selection is cleared.
Returns:
Description: Returns a list of selected objects for a given document name. If no document is given the complete selection is returned.
Returns: a list of objects
Placement
A placement in FreeCAD is an object defining a position and a rotation. A placement can then be added to a FreeCAD Object, to orient/position it in the document. Example:
myObj = FreeCAD.ActiveDocument.ActiveObject pl = FreeCAD.Placement() pl.move(FreeCAD.Vector(2,0,0)) myObj.Placement = pl
Description: Constructs a placement, empty or with the given arguments, or as a copy of the given placement.
Description: applies the Placement to the given vector
Returns: the resulting vector.
Description: multiplies this placement with another one
Returns: the resulting placement.
Document Objects
Being parametric, document objects in FreeCAD can have a lot of additional properties, but these are the basic ones, present in every FreeCAD Document Object. Objects can be retrieved simply by their name. Example:
myObj = FreeCAD.ActiveDocument.myObjectName print myObj.PropertiesList
Returns: Gets/sets the Placement of an object. A placement defines an orientation (rotation) and a position (base) in 3D space. It is used when no scaling or other distortion is needed.
Description:
Returns: the documentation string of the property of this class.
Description:
Returns: the name of the group which the property belongs to in this class. The properties sorted in differnt named groups for convenience.
Description:
Returns: the type of a named property. This can be (Hidden,ReadOnly,Output) or any combination.
View Objects
When the GUI is up, each object in the FreeCAD document has an associated ViewObject, that resides in the FreeCADGui document counterpart. A view object can be retrieved by two ways. Example:
myViewObj = FreeCAD.ActiveDocument.myObjectName.ViewObject myViewObj = FreeCADGui.ActiveDocument.myObjectName print myViewObj.IV
Description:
Returns: the documentation string of the property of this class.
Description:
Returns: the name of the group which the property belongs to in this class. The properties sorted in differnt named groups for convenience.
Description:
Returns: the type of a named property. This can be (Hidden,ReadOnly,Output) or any combination.
Description: Checks if this object is derived from the given object type
Returns: True if given type is a father
Description: Sets a transformation on the Inventor node
Returns: nothing