App FeaturePython

From FreeCAD Documentation
Revision as of 20:23, 14 May 2020 by Renatorivo (talk | contribs) (Created page with "Oltre alle proprietà descritte in App DocumentObject, FeaturePython ha un provider di visualizzazione di base, quindi appare nella tree view/it|vi...")
Other languages:

Introduzione

Un oggetto App FeaturePython, o formalmente un App::FeaturePython, è una semplice istanza di App DocumentObject in Python.

Questo è un oggetto semplice che per impostazione predefinita non ha molte proprietà, ad esempio nessun posizionamentoforma topologica. Questo oggetto è per uso generale e, fornendolo di proprietà, può essere utilizzato per gestire diversi tipi di dati.

Diagramma semplificato delle relazioni tra gli oggetti principali del programma. La classe App::FeaturePython è una semplice implementazione di App::DocumentObject che può essere utilizzata per qualsiasi scopo, poiché di default non ha una forma topologica.

Utilizzo

Un App FeaturePython è un oggetto interno, quindi non può essere creato dall'interfaccia grafica. È pensato per essere sottoclassato da classi che gestiranno diversi tipi di dati.

Vedere Script per ulteriori informazioni.

Proprietà

Un oggetto App FeaturePython (classe App::FeaturePython) è derivato dall'oggetto base App DocumentObject (classe App::DocumentObject), pertanto condivide tutte le proprietà di quest'ultimo.

Oltre alle proprietà descritte in App DocumentObject, FeaturePython ha un provider di visualizzazione di base, quindi appare nella vista ad albero.

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.

Dati

Base

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

Hidden properties Data

  • DatiExpression Engine (ExpressionEngine): a list of expressions. By default, it is empty [].
  • DatiLabel2 (String): a longer, user editable description of this object, it is an arbitrary UTF8 string that may include newlines. By default, it is an empty string "".
  • DatiProxy (PythonObject): a custom class associated with this object.
  • DatiVisibility (Bool): whether to display the object or not.

Vista

Base

  • VistaDisplay Mode (Enumeration): it is empty by default.
  • VistaOn Top When Selected (Enumeration): Disabled (default), Enabled, Object, Element.
  • VistaSelection 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.
  • VistaShow In Tree (Bool): if it is true, the object appears in the tree view. Otherwise, it is set as invisible.
  • VistaVisibility (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

  • VistaProxy (PythonObject): a custom view provider class associated with this object.

Script

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 and additional properties. They hold data but not an actual Part TopoShape.

If the desired object should have a placement, a shape, an attachment, or other complex properties, it is better to create one of the more complex classes, for example, App GeoFeature, Part Feature, or Part Part2DObject.