App FeaturePython: Difference between revisions

From FreeCAD Documentation
(Use the second argument of the PropertyData template for the types.)
(Use the second argument of the PropertyView template for the types.)
Line 61: Line 61:


<!--T:20-->
<!--T:20-->
* {{PropertyView|Display Mode}}: it is empty by default.
* {{PropertyView|Display Mode|Enumeration}}: it is empty by default.
* {{PropertyView|On Top When Selected}}: {{value|Disabled}} (default), {{value|Enabled}}, {{value|Object}}, {{value|Element}}.
* {{PropertyView|On Top When Selected|Enumeration}}: {{value|Disabled}} (default), {{value|Enabled}}, {{value|Object}}, {{value|Element}}.
* {{PropertyView|Selection Style}}: {{value|Shape}} (default), {{value|BoundBox}}. If the option is {{value|Shape}}, the entire shape (vertices, edges, and faces) will be highlighted in the [[3D view|3D view]]; if it is {{value|BoundBox}} only the bounding box will be highlighted.
* {{PropertyView|Selection Style|Enumeration}}: {{value|Shape}} (default), {{value|BoundBox}}. If the option is {{value|Shape}}, the entire shape (vertices, edges, and faces) will be highlighted in the [[3D view|3D view]]; if it is {{value|BoundBox}} only the bounding box will be highlighted.
* {{PropertyView|Show In Tree}}: if it is {{TRUE}}, the object appears in the [[tree view|tree view]]. Otherwise, it is set as invisible.
* {{PropertyView|Show In Tree|Bool}}: if it is {{TRUE}}, the object appears in the [[tree view|tree view]]. Otherwise, it is set as invisible.
* {{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|Bool}}: 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 ==== <!--T:21-->
==== Hidden properties View ==== <!--T:21-->


<!--T:22-->
<!--T:22-->
* {{PropertyView|Proxy}}: a custom view provider class associated with this object. By default it is empty.
* {{PropertyView|Proxy|PythonObject}}: a custom view provider class associated with this object. By default it is empty.


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

Revision as of 06:02, 19 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 TopoShape 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. Hidden properties can be shown by using the Show all command in the context menu of the property editor.

Data

Base

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

Hidden properties Data

  • DataExpression Engine (ExpressionEngine): a list of expressions. By default, it is empty [].
  • DataLabel2 (String): a longer, user editable description of this object, it is an arbitrary UTF8 string. By default, it is an empty string "".
  • DataProxy (PythonObject): a custom class associated with this object.
  • DataVisibility (Bool): whether to display the object or not.

View

Base

  • ViewDisplay Mode (Enumeration): it is empty by default.
  • ViewOn Top When Selected (Enumeration): Disabled (default), Enabled, Object, Element.
  • ViewSelection Style (Enumeration): Shape (default), BoundBox. If the option is Shape, the entire shape (vertices, edges, and faces) will be highlighted in the 3D view; if it is BoundBox only the bounding box will be highlighted.
  • ViewShow In Tree (Bool): if it is true, the object appears in the tree view. Otherwise, it is set as invisible.
  • ViewVisibility (Bool): 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 (PythonObject): a custom view provider class associated with this object. By default it is empty.

Scripting

See also: FreeCAD Scripting Basics, and scripted objects.

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

An App 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"

For example, the Draft Text, Draft Dimension, and Working plane proxy elements of the Draft Workbench are App::FeaturePython objects with a custom icon. They hold data but not an actual Part TopoShape.