App DocumentObject: Difference between revisions
m (→Scripting: It is usually better to create one of the sub-classes, for example, App FeaturePython, Part Feature, or Part Part2DObject.) |
(→Properties: For derived objects, only "Label" will be listed in the property editor by default. The other properties will be hidden.) |
||
Line 26: | Line 26: | ||
These are the basic properties that essentially all objects have. These properties can be accessed from the [[Python console|Python console]]. |
These are the basic properties that essentially all objects have. These properties can be accessed from the [[Python console|Python console]]. |
||
* {{PropertyData| |
* {{PropertyData|Expression Engine}}: a list of expressions. |
||
* {{PropertyData|Label}}: the user editable name of this object. |
* {{PropertyData|Label}}: the user editable name of this object, it is an arbitrary UTF8 string. |
||
* {{PropertyData|Label2}}: a longer, user editable description of this object. |
* {{PropertyData|Label2}}: a longer, user editable description of this object, it is an arbitrary UTF8 string. |
||
* {{PropertyData|Visibility}}: whether to display the object or not. |
* {{PropertyData|Visibility}}: whether to display the object or not. |
||
For derived objects, only {{PropertyData|Label}} will be listed in the [[property editor|property editor]] by default. The other properties will be hidden. |
|||
== Scripting == |
== Scripting == |
Revision as of 06:50, 16 December 2019
Introduction
An App DocumentObject object, or formally an App::DocumentObject
, is the base class of all object classes handled in the document.
Simplified diagram of the relationships between the core objects in the program. The App::DocumentObject
class is the base class of essentially all objects in the software.
How to use
The App DocumentObject is an internal object, so it cannot be created from the graphical interface. It is not meant to be used directly; rather, it is meant to be sub-classed by classes that will handle different types of data. Therefore, almost every object in the software, that is, every element that has an icon and that can be listed in the tree view, is a "DocumentObject".
Some of the most important DocumentObjects are the following:
- The App GeoFeature class, which is the base object of all geometrical objects, that is, of objects that have a Placement property that defines their position in the 3D view.
- The Part Feature class, which is derived from App GeoFeature, and which is the parent class of objects with 2D and 3D shapes.
Properties
These are the basic properties that essentially all objects have. These properties can be accessed from the Python console.
- DataExpression Engine: a list of expressions.
- DataLabel: the user editable name of this object, it is an arbitrary UTF8 string.
- DataLabel2: a longer, user editable description of this object, it is an arbitrary UTF8 string.
- DataVisibility: whether to display the object or not.
For derived objects, only DataLabel will be listed in the property editor by default. The other properties will be hidden.
Scripting
See also: FreeCAD Scripting Basics, and scripted objects.
See Part Feature for the general information on adding objects to the program.
A DocumentObject is created with the addObject()
method of the document. However, in general, there is no need to create this object manually. It is usually better to create one of the sub-classes, for example, App FeaturePython, Part Feature, or Part Part2DObject.
import FreeCAD as App
doc = App.newDocument()
obj = App.ActiveDocument.addObject("App::DocumentObject", "Name")
obj.Label = "Custom label"
- Getting started
- Installation: Download, Windows, Linux, Mac, Additional components, Docker, AppImage, Ubuntu Snap
- Basics: About FreeCAD, Interface, Mouse navigation, Selection methods, Object name, Preferences, Workbenches, Document structure, Properties, Help FreeCAD, Donate
- Help: Tutorials, Video tutorials
- Workbenches: Std Base, Arch, Assembly, CAM, Draft, FEM, Inspection, Mesh, OpenSCAD, Part, PartDesign, Points, Reverse Engineering, Robot, Sketcher, Spreadsheet, Start, Surface, TechDraw, Test Framework, Web
- Hubs: User hub, Power users hub, Developer hub