App DocumentObject

From FreeCAD Documentation
Revision as of 15:23, 26 December 2019 by David69 (talk | contribs) (Created page with "Voir Propriétés pour tous les types de propriétés que les objets crées par script peuvent avoir.")
Other languages:

Introduction

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

Diagramme simplifié des relations entre les objets centraux du programme. La classe App::DocumentObject est la classe de base de pratiquement tous les objets du logiciel.

Utilisation

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

Propriétés

Voir Propriétés pour tous les types de propriétés que les objets crées par script peuvent avoir.

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

  • DonnéesExpression Engine (ExpressionEngine): a list of expressions.
  • DonnéesLabel (String): the user editable name of this object, it is an arbitrary UTF8 string.
  • DonnéesLabel2 (String): a longer, user editable description of this object, it is an arbitrary UTF8 string.
  • DonnéesVisibility (Bool): whether to display the object or not.

For derived objects, only DonnéesLabel will be listed in the property editor by default. The other properties will be hidden.

Script

Voir aussi: Débuter avec les scripts et Objets créés par script.

Voir Part Feature pour les informations générales sur l'ajout d'objets au programme.

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"