Builtin modules: Difference between revisions

From FreeCAD Documentation
No edit summary
(21 intermediate revisions by 5 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<!--T:13-->
{{VeryImportantMessage|(October 2019) Do not edit these pages. The information is incomplete and outdated. For the latest API, see the [https://www.freecadweb.org/api autogenerated API documentation], or generate the documentation yourself, see [[Source documentation|Source documentation]].}}

<!--T:12-->
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.
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.
</translate>
__NOTOC__
<translate>
=== [[FreeCAD_API|The FreeCAD module]] === <!--T:1-->


=== The FreeCAD module ===
=== [[Base_API|Base]] === <!--T:2-->

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()

{{APIFunction|ConfigDump| |Prints a dictionnnary containing all the FreeCAD configuration environment.| }}

{{APIFunction|ConfigGet|[string]|Returns the value of the given key. If no key is given, the complete configuration is returned|A string.}}

{{APIFunction|ConfigSet|string, string|Set the given key (first string) to the given value (second string).| }}

{{APIFunction|Version| |Prints the FreeCAD version.| }}

{{APIFunction|activeDocument| ||Return the active document or None if there is no active document.|A FreeCAD Document.}}

{{APIFunction|addExportType|string, string|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.| }}

{{APIFunction|addImportType|string, string|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.| }}

{{APIFunction|closeDocument|Document name|Closes the given document| }}

{{APIFunction|getDocument|Document name|Returns a document or raise an exception if there is no document with the given name.| }}

{{APIFunction|getExportType|string|Returns the name of the module that can export the specified filetype.| A string.}}

{{APIFunction|getImportType|string|Returns the name of the module that can import the specified filetype.|A string.}}

{{APIFunction|listDocuments| |Returns a list of names of all documents.|A list of names.}}

{{APIFunction|newDocument|[string]|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".|The newly created document.}}

{{APIFunction|open|string|See openDocument| }}

{{APIFunction|openDocument|filepath|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.|The opened FreeCAD Document.}}

{{APIFunction|setActiveDocument|Document name|Set the active document by its name.| }}

=== Base ===

The Base module is contained inside the FreeCAD module and contains constructors for different types of objects heavily used in FreeCAD.

{{APIClass|BoundBox|[Xmin,Ymin,Zmin,Xmax,Ymax,Zmax] ) or ( Tuple, Tuple ) or ( Vector, Vector|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!}}

{{APIClass|Matrix| |Creates a 4x4 matrix, that can be used to apply transformations to objects.}}

{{APIClass|Vector|x,y,z|Creates a FreeCAD 3D vector, representing a 3D point or a direction.}}

=== 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

{{APIProperty|Length|returns the length of the vector.}}

{{APIFunction|add|Vector|adds another vector to this one|the sum of both vectors.}}

{{APIFunction|cross|Vector| |the crossproduct between two vectors.}}

{{APIFunction|distanceToLine|Vector1,Vector2| |the distance between the vector and a line between Vector1 and Vector2.}}

{{APIFunction|distanceToPlane|Vector1,Vector2| |the distance between the vector and a plane defined by a point and a normal.}}

{{APIFunction|dot|Vector| |the dot product between 2 vectors.}}

{{APIFunction|getAngle|Vector| |the angle in radians between 2 vectors.}}

{{APIFunction|multiply|Float|multiplies (scales) a vector by the given factor|nothing.}}

{{APIFunction|normalize| |normalizes a vector (sets its length to 1.0).|nothing.}}

{{APIFunction|projectToLine|Vector1,Vector2|projects the vector on a line between Vector1 and Vector2.|nothing.}}

{{APIFunction|projectToPlane|Vector1,Vector2|projects the vector on a plane defined by a point and a normal.|nothing.}}

{{APIFunction|scale|Float,Float,Float|Same as multiply but lets specify different values for x, y and z directions.|nothing.}}

{{APIFunction|sub|Vector|subtracts another vector from the first one.|the resulting vector.}}

{{APIProperty|x|the x coordinate of a vector.}}

{{APIProperty|y|the y coordinate of a vector.}}

{{APIProperty|z|the z coordinate of a vector.}}

=== Matrixes ===

Matrixes can be created by one of the following manners:

m=FreeCAD.Matrix()
m=FreeCAD.Base.Matrix()
print m.A21()

{{PIFunction|A| | |all the matrix elements.}}

{{PIFunction|A11| | |a matrix element.}}

{{PIFunction|A12| | |a matrix element.}}

{{PIFunction|A13| | |a matrix element.}}

{{PIFunction|A14| | |a matrix element.}}

{{PIFunction|A21| | |a matrix element.}}

{{PIFunction|A22| | |a matrix element.}}

{{PIFunction|A23| | |a matrix element.}}

{{PIFunction|A24| | |a matrix element.}}

{{PIFunction|A31| | |a matrix element.}}

{{PIFunction|A32| | |a matrix element.}}

{{PIFunction|A33| | |a matrix element.}}

{{PIFunction|A34| | |a matrix element.}}

{{PIFunction|A41| | |a matrix element.}}

{{PIFunction|A42| | |a matrix element.}}

{{PIFunction|A43| | |a matrix element.}}

{{PIFunction|A44| | |a matrix element.}}

{{APIFunction|determinant|Float|Computes the determinant of the matrix|the matrix determinant.}}

{{APIFunction|inverse| |Computes the inverse matrix, if possible|a Matrix}}

{{APIFunction|invert| |Computes the inverse matrix, if possible|a Matrix}}

{{APIFunction|move|Vector|Moves the matrix along the vector|nothing.}}

{{APIFunction|multiply|Matrix or Vector|Multiplies a matrix or vector with this matrix|nothing.}}

{{APIFunction|rotateX|Float|rotates the matrix around X axis (in radians)|nothing.}}

{{APIFunction|rotateY|Float|rotates the matrix around Y axis (in radians)|nothing.}}

{{APIFunction|rotateZ|Float|rotates the matrix around Z axis (in radians)|nothing.}}

{{APIFunction|scale|Vector|Scales the matrix with the vector|nothing.}}

{{APIFunction|transform|Vector or Matrix|returns the dot product of the two vectors| }}

{{APIFunction|unity| |makes this matrix to unity|nothing.}}

=== Console sub-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.

* '''GetStatus(...)''' - Get the status for either Log, Msg, Wrn or Error for an observer
* '''PrintError(string)''' - Print an error message to the output
* '''PrintLog(string)''' - Print a log message to the output
* '''PrintMessage(string)''' - Print a message to the output
* '''PrintWarning(string)''' - Print a warning to the output
* '''SetStatus(...)''' - Set the stats for either Log, Msg, Wrn or Error for an observer

=== The FreeCADGui Module ===

This module is the counterpart of the FreeCAD module. It contains everything related to the User interface and the 3D views.

* '''activateWorkbench(string)''' - Activate the workbench by name
* '''activeDocument()''' - Return the active document or None if no one exists
* '''activeWorkbench()''' - Return the active workbench object
* '''addCommand(string, object)''' - Add a command
* '''addIcon(string, string or list)''' - Add an icon as file name or in XPM format to the system
* '''addIconPath(string)''' - Add a new path to the system where to find icon files
* '''addPreferencePage(string,string)''' - Add a UI form to the preferences dialog. The first argument specifies the file nameand the second specifies the group name
* '''addWorkbench(string, object)''' - Add a workbench under a defined name.
* '''createDialog(string)''' - Open a UI file
* '''getDocument(string)''' - Get a document by its name
* '''getWorkbench(string)''' - Get the workbench by its name
* '''insert(...)''' - Open a macro, Inventor or VRML file
* '''listWorkbenches() - Show a list of all workbenches
* '''open(...)''' - Open a macro, Inventor or VRML file
* '''removeWorkbench(string)''' - Remove the workbench with name
* '''runCommand(string)''' - Run command with name
* '''updateGui()''' - Update the main window and all its windows

=== Selection sub-module ===


=== [[Vector_API|Vectors]] === <!--T:3-->
The selection submodule is part of the FreeCADGui module.


=== [[Matrix_API|Matrixes]] === <!--T:4-->
* '''addSelection(object)''' - Add an object to the selection
* '''clearSelection([string])''' - Clear the selection to the given document name. If no document is given the complete selection is cleared.
* '''getSelection([string])''' - Return a list of selected objects for a given document name. If no document is given the complete selection is returned.
* '''isSelected(object)''' - Check if a given object is selected
* '''removeSelection(object)''' - Remove an object from the selection


=== [[Console_API|Console module]] === <!--T:5-->
=== Document Objects ===


=== [[FreeCADGui_API|The FreeCADGui Module]] === <!--T:6-->
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:


=== [[Selection_API|Selection module]] === <!--T:7-->
myObj = FreeCAD.ActiveDocument.myObjectName


=== [[Placement_API|Placement]] === <!--T:8-->
* '''Object.Content''' - Return an XML representation of the properties of an object.
* '''Object.Label''' - Gets/sets the objects label. The string can be unicode.
* '''Object.Name''' - Returns the unique name of an object
* '''Object.Placement''' - 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. The following constructors are supported:
** '''Placement()''' - empty constructor
** '''Placement(Placement)''' - copy constructor
** '''Placement(Matrix)''' - 4D matrix consisting of rotation and translation
** '''Placement(Base, Rotation)''' - define position and rotation
** '''Placement(Base, Rotation,Center)''' - define position and rotation with center
** '''Placement(Base, Axis, Angle)''' - define position and rotation
* '''Object.Pos''' - returns the position part of the placement
* '''Object.PropertiesList''' - returns a list of the properties of an object
* '''Object.State''' - returns the FreeCAD state of an object (ie. if it needs to be recomputed)
* '''Object.Type''' - returns a string describing the type of an object
* '''Object.ViewObject''' - returns the associated View Provider (FreeCADGUI object) of an object
* '''Object.getAllDerivedFrom()''' - Returns all descentences
* '''Object.getDocumentationOfProperty()''' - Return the documentation string of the property of this class.
* '''Object.getGroupOfProperty()''' - Return the name of the group which the property belongs to in this class. The properties sorted in differnt named groups for convenience.
* '''Object.getPropertyByName()''' - Return the value of a named property.
* '''Object.getTypeOfProperty()''' - Return the type of a named property. This can be (Hidden,ReadOnly,Output) or any combination.
* '''Object.isDerivedFrom()''' - Returns true if given type is a father
* '''Object.purgeTouched()''' - Mark the object as unchanged
* '''Object.touch()''' - Mark the object as changed (touched)


=== View Objects ===
=== [[Object_API|Document Objects]] === <!--T:9-->


=== [[ViewObject_API|View Objects]] === <!--T:10-->
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:


</translate>
myViewObj = FreeCAD.ActiveDocument.myObjectName.ViewObject
{{Userdocnavi{{#translation:}}}}
myViewObj = FreeCADGui.ActiveDocument.myObjectName
[[Category:API{{#translation:}}]]
[[Category:Poweruser Documentation{{#translation:}}]]


* '''ViewObject.Annotation''' - the annotation node of a ViewObject
* '''ViewObject.BoundingBox''' - the bounding box
* '''ViewObject.Content''' - returns an XML representation of a ViewObject's properties
* '''ViewObject.DisplayMode''' - returns the current display mode
* '''ViewObject.IV''' - returns an Inventor representation of the ViewObject
* '''ViewObject.Object''' - returns the associated FreeCAD Document Object of this ViewObject
* '''ViewObject.PropertiesList''' - returns a list of properties of this ViewObject
* '''ViewObject.RootNode''' - returns the Inventor node of this ViewObject
* '''ViewObject.Selectable''' - returns True if the object is selectable
* '''ViewObject.Type''' - returns the type of this ViewObject
* '''ViewObject.Visibility''' - returns True if the viewObject is visible
* '''ViewObject.getAllDerivedFrom()''' - Returns all descentences
* '''ViewObject.getDocumentationOfProperty()''' - Return the documentation string of the property of this class.
* '''ViewObject.getGroupOfProperty()''' - Return the name of the group which the property belongs to in this class. The properties sorted in differnt named groups for convenience.
* '''ViewObject.getPropertyByName()''' - Return the value of a named property.
* '''ViewObject.getTypeOfProperty()''' - Return the type of a named property. This can be (Hidden,ReadOnly,Output) or any combination.
* '''ViewObject.hide()''' - Hides the object
* '''ViewObject.isDerivedFrom()''' - Returns true if given type is a father
* '''ViewObject.isVisible()''' - Check if the object is visible
* '''ViewObject.listDisplayModes()''' - Show a list of all display modes
* '''ViewObject.setTransformation()''' - Set a transformation on the Inventor node
* '''ViewObject.show()''' - Show the object
* '''ViewObject.toString()''' - Return a string representation of the Inventor node
* '''ViewObject.update()''' - Update the view representation of the object


{{clear}}
[[Category:API]]
[[Category:Poweruser Documentation]]

Revision as of 20:53, 27 February 2020

(October 2019) Do not edit these pages. The information is incomplete and outdated. For the latest API, see the autogenerated API documentation, or generate the documentation yourself, see Source documentation.

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

Base

Vectors

Matrixes

Console module

The FreeCADGui Module

Selection module

Placement

Document Objects

View Objects