App DocumentObject: Difference between revisions

From FreeCAD Documentation
(* The Mesh Feature class, derived from App GeoFeature, and the parent class of objects with 2D and 3D meshes.)
(a longer, user editable description of this object, it is an arbitrary UTF8 string that may include newlines.)
Line 42: Line 42:
* {{PropertyData|Expression Engine|ExpressionEngine}}: a list of expressions.
* {{PropertyData|Expression Engine|ExpressionEngine}}: a list of expressions.
* {{PropertyData|Label|String}}: the user editable name of this object, it is an arbitrary UTF8 string.
* {{PropertyData|Label|String}}: the user editable name of this object, it is an arbitrary UTF8 string.
* {{PropertyData|Label2|String}}: a longer, user editable description of this object, it is an arbitrary UTF8 string.
* {{PropertyData|Label2|String}}: a longer, user editable description of this object, it is an arbitrary UTF8 string that may include newlines.
* {{PropertyData|Visibility|Bool}}: whether to display the object or not.
* {{PropertyData|Visibility|Bool}}: whether to display the object or not.



Revision as of 05:41, 11 January 2020

Introduction

An App DocumentObject object, or formally an App::DocumentObject, is the base class of all object classes handled in the document.

In general terms, a "DocumentObject" is any "thing" that can appear in the tree view, and which is saved and restored when opening a 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 class, so it cannot be created from the graphical interface, nor is it meant to be used by itself. It just defines the basic behavior and properties of objects in the software.

Some of the most important DocumentObjects are the following:

  • The App FeaturePython class, an empty object that can be used for different purposes, depending on the added properties.
  • The App GeoFeature class, 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, derived from App GeoFeature, and the parent class of objects with 2D and 3D topological shapes.
  • The Mesh Feature class, derived from App GeoFeature, and the parent class of objects with 2D and 3D meshes.

Properties

See Property for all property types that scripted objects can have.

These are the basic properties that essentially all objects have. These properties can be accessed from the Python console.

  • DataExpression Engine (ExpressionEngine): a list of expressions.
  • DataLabel (String): the user editable name of this object, it is an arbitrary UTF8 string.
  • DataLabel2 (String): a longer, user editable description of this object, it is an arbitrary UTF8 string that may include newlines.
  • DataVisibility (Bool): 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"