App FeaturePython: Difference between revisions

From FreeCAD Documentation
(Marked this version for translation)
Line 2: Line 2:
<translate>
<translate>


== Introduction ==
== Introduction == <!--T:1-->


</translate>
</translate>
Line 8: Line 8:
<translate>
<translate>


<!--T:2-->
An [[App_FeaturePython|App FeaturePython]] object, or formally an {{incode|App::FeaturePython}}, is a simple instance of the [[App_DocumentObject|App DocumentObject]] in [[Python|Python]]. This is a simple object that by default doesn't have many properties, for example, no [[Placement|placement]] nor [[Part_TopoShape|topological shape]]. This object is for general purpose use, and by giving properties to it, it can be used to manage different types of data.
An [[App_FeaturePython|App FeaturePython]] object, or formally an {{incode|App::FeaturePython}}, is a simple instance of the [[App_DocumentObject|App DocumentObject]] in [[Python|Python]]. This is a simple object that by default doesn't have many properties, for example, no [[Placement|placement]] nor [[Part_TopoShape|topological shape]]. This object is for general purpose use, and by giving properties to it, it can be used to manage different types of data.


<!--T:3-->
[[File:FreeCAD_core_objects.svg|800px]]
[[File:FreeCAD_core_objects.svg|800px]]


<!--T:4-->
{{Caption|Simplified diagram of the relationships between the core objects in the program. The {{incode|App::FeaturePython}} class is a simple implementation of the {{incode|App::DocumentObject}} that can be used for any purpose, as it doesn't have a shape by default.}}
{{Caption|Simplified diagram of the relationships between the core objects in the program. The {{incode|App::FeaturePython}} class is a simple implementation of the {{incode|App::DocumentObject}} that can be used for any purpose, as it doesn't have a shape by default.}}


== How to use ==
== How to use == <!--T:5-->


<!--T:6-->
The [[App_FeaturePython|App FeaturePython]] is an internal object, so it cannot be created from the graphical interface. It is meant to be sub-classed by classes that will handle different types of data.
The [[App_FeaturePython|App FeaturePython]] is an internal object, so it cannot be created from the graphical interface. It is meant to be sub-classed by classes that will handle different types of data.


<!--T:7-->
See [[App_FeaturePython#Scripting|Scripting]] for more information.
See [[App_FeaturePython#Scripting|Scripting]] for more information.


== Properties ==
== Properties == <!--T:8-->


<!--T:9-->
An [[App_FeaturePython|App FeaturePython]] ({{incode|App::FeaturePython}} class) is derived from the basic [[App_DocumentObject|App DocumentObject]] ({{incode|App::DocumentObject}} class), therefore it shares all the latter's properties.
An [[App_FeaturePython|App FeaturePython]] ({{incode|App::FeaturePython}} class) is derived from the basic [[App_DocumentObject|App DocumentObject]] ({{incode|App::DocumentObject}} class), therefore it shares all the latter's properties.


<!--T:10-->
In addition to the properties described in [[App_DocumentObject|App DocumentObject]], the FeaturePython has a basic view provider, so it does appear in the [[tree view|tree view]].
In addition to the properties described in [[App_DocumentObject|App DocumentObject]], the FeaturePython has a basic view provider, so it does appear in the [[tree view|tree view]].


<!--T:11-->
See [[Property|Property]] for all property types that scripted objects can have.
See [[Property|Property]] for all property types that scripted objects can have.


<!--T:12-->
These are the properties available in the [[property editor|property editor]].
These are the properties available in the [[property editor|property editor]].


=== Data ===
=== Data === <!--T:13-->


<!--T:14-->
{{TitleProperty|Base}}
{{TitleProperty|Base}}


<!--T:15-->
* {{PropertyData|Label}}: the user editable name of this object, it is an arbitrary UTF8 string.
* {{PropertyData|Label}}: the user editable name of this object, it is an arbitrary UTF8 string.


==== Hidden properties Data ====
==== Hidden properties Data ==== <!--T:16-->


<!--T:17-->
* {{PropertyData|Expression Engine}}: a list of expressions.
* {{PropertyData|Expression Engine}}: a list of expressions.
* {{PropertyData|Label2}}: a longer, user editable description of this object, it is an arbitrary UTF8 string.
* {{PropertyData|Label2}}: a longer, user editable description of this object, it is an arbitrary UTF8 string.
Line 43: Line 55:
* {{PropertyData|Visibility}}: whether to display the object or not.
* {{PropertyData|Visibility}}: whether to display the object or not.


=== View ===
=== View === <!--T:18-->


<!--T:19-->
{{TitleProperty|Base}}
{{TitleProperty|Base}}


<!--T:20-->
* {{PropertyView|Display Mode}}: it is empty by default.
* {{PropertyView|Display Mode}}: it is empty by default.
* {{PropertyView|On Top When Selected}}: {{value|Disabled}}, {{value|Enabled}}, {{value|Object}}, {{value|Element}}.
* {{PropertyView|On Top When Selected}}: {{value|Disabled}}, {{value|Enabled}}, {{value|Object}}, {{value|Element}}.
Line 53: Line 67:
* {{PropertyView|Visibility}}: if it is {{TRUE}}, the object appears in the [[3D view|3D view]]; otherwise it is invisible. By default this property can be toggled on and off by pressing the {{KEY|Space}} bar in the keyboard.
* {{PropertyView|Visibility}}: if it is {{TRUE}}, the object appears in the [[3D view|3D view]]; otherwise it is invisible. By default this property can be toggled on and off by pressing the {{KEY|Space}} bar in the keyboard.


==== Hidden properties View ====
==== Hidden properties View ==== <!--T:21-->


<!--T:22-->
* {{PropertyView|Proxy}}: a class associated with this view provider.
* {{PropertyView|Proxy}}: a class associated with this view provider.


== Scripting ==
== Scripting == <!--T:23-->


<!--T:24-->
{{Emphasis|See also:}} [[FreeCAD Scripting Basics|FreeCAD Scripting Basics]], and [[scripted objects|scripted objects]].
{{Emphasis|See also:}} [[FreeCAD Scripting Basics|FreeCAD Scripting Basics]], and [[scripted objects|scripted objects]].


<!--T:25-->
See [[Part_Feature|Part Feature]] for the general information on adding objects to the program.
See [[Part_Feature|Part Feature]] for the general information on adding objects to the program.


<!--T:26-->
A FeaturePython is created with the {{incode|addObject()}} method of the document.
A FeaturePython is created with the {{incode|addObject()}} method of the document.


Line 75: Line 93:
<translate>
<translate>


<!--T:27-->
{{Userdocnavi}}
{{Userdocnavi}}
</translate>
</translate>

Revision as of 20:31, 16 December 2019

Introduction

An App FeaturePython object, or formally an App::FeaturePython, is a simple instance of the App DocumentObject in Python. This is a simple object that by default doesn't have many properties, for example, no placement nor topological shape. This object is for general purpose use, and by giving properties to it, it can be used to manage different types of data.

Simplified diagram of the relationships between the core objects in the program. The App::FeaturePython class is a simple implementation of the App::DocumentObject that can be used for any purpose, as it doesn't have a shape by default.

How to use

The App FeaturePython is an internal object, so it cannot be created from the graphical interface. It is meant to be sub-classed by classes that will handle different types of data.

See Scripting for more information.

Properties

An App FeaturePython (App::FeaturePython class) is derived from the basic App DocumentObject (App::DocumentObject class), therefore it shares all the latter's properties.

In addition to the properties described in App DocumentObject, the FeaturePython has a basic view provider, so it does appear in the tree view.

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

These are the properties available in the property editor.

Data

Base

  • DataLabel: the user editable name of this object, it is an arbitrary UTF8 string.

Hidden properties Data

  • DataExpression Engine: a list of expressions.
  • DataLabel2: a longer, user editable description of this object, it is an arbitrary UTF8 string.
  • ViewProxy: a class associated with this object.
  • DataVisibility: whether to display the object or not.

View

Base

  • ViewDisplay Mode: it is empty by default.
  • ViewOn Top When Selected: Disabled, Enabled, Object, Element.
  • ViewSelection Style: Shape, BoundBox.
  • ViewShow In Tree: if it is true, the object appears in the tree view. Otherwise, it is set as invisible.
  • ViewVisibility: if it is true, the object appears in the 3D view; otherwise it is invisible. By default this property can be toggled on and off by pressing the Space bar in the keyboard.

Hidden properties View

  • ViewProxy: a class associated with this view provider.

Scripting

See also: FreeCAD Scripting Basics, and scripted objects.

See Part Feature for the general information on adding objects to the program.

A FeaturePython is created with the addObject() method of the document.

import FreeCAD as App

doc = App.newDocument()
obj = App.ActiveDocument.addObject("App::FeaturePython", "Name")
obj.Label = "Custom label"