Property: Difference between revisions

From FreeCAD Documentation
m (→‎Scripting: scripted)
(Removed a reference to V0.19.)
 
(38 intermediate revisions by 6 users not shown)
Line 2: Line 2:
<translate>
<translate>


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


<!--T:1-->
<!--T:1-->
Line 8: Line 8:


<!--T:4-->
<!--T:4-->
Properties play a very important role in FreeCAD. As objects in FreeCAD are "parametric", this means that their behavior is defined by their properties, and how these properties are used as input for their class methods.
Properties play a very important role in FreeCAD. As objects in FreeCAD are "parametric", this means that their behavior is defined by their properties, and how these properties are used as input for their class methods. See also [[FeaturePython_Custom_Properties|FeaturePython Custom Properties]] and [[PropertyLink:_InList_and_OutList|PropertyLink: InList and OutList]]


== All properties ==
== All property types == <!--T:9-->


<!--T:5-->
<!--T:5-->
Custom [[scripted objects|scripted objects]] can use any of the property types defined in the base system:
Custom [[Scripted_objects|scripted objects]] can use any of the property types defined in the base system:

</translate>
</translate>
{| class="sortable wikitable"
{{Code|code=
|-
Bool
! Name !! Unit (if any) !! Remark
Float
|-
FloatList
| Acceleration || style="text-align:center;" | m/s^2
FloatConstraint
|-
Angle
| AmountOfSubstance || style="text-align:center;" | mol
Distance
|-
Integer
| Angle || style="text-align:center;" | °
IntegerConstraint
|-
Percent
| Area || style="text-align:center;" | m^2
Enumeration
|-
IntegerList
| Bool ||
String
|-
StringList
| BoolList ||
Length
|-
Link
| Color ||
LinkList
|-
LinkSubList
| ColorList ||
Matrix
|-
Vector
| CurrentDensity || style="text-align:center;" | A/m^2 || {{Version|0.21}}
VectorList
|-
VectorDistance
| Density || style="text-align:center;" | kg/m^3
Placement
|-
PlacementLink
| Direction ||
Color
|-
ColorList
| DissipationRate || style="text-align:center;" | m^2/s^3 || {{Version|0.21}}
Material
|-
Path
| Distance || style="text-align:center;" | m
File
|-
FileIncluded
| DynamicViscosity || style="text-align:center;" | Pa*s || {{Version|0.21}}
PartShape
|-
FilletContour
| ElectricalCapacitance || style="text-align:center;" | F || {{Version|0.21}}
Circle
|-
}}
| ElectricalConductance || style="text-align:center;" | S || {{Version|0.21}}
|-
| ElectricalConductivity || style="text-align:center;" | S/m || {{Version|0.21}}
|-
| ElectricalInductance|| style="text-align:center;" | H || {{Version|0.21}}
|-
| ElectricalResistance || style="text-align:center;" | Ohm || {{Version|0.21}}
|-
| ElectricCharge || style="text-align:center;" | C || {{Version|0.21}}
|-
| ElectricCurrent || style="text-align:center;" | A || {{Version|0.21}}
|-
| ElectricPotential || style="text-align:center;" | V || {{Version|0.20}}
|-
| Enumeration ||
|-
| ExpressionEngine ||
|-
| File ||
|-
| FileIncluded ||
|-
| Float ||
|-
| FloatConstraint ||
|-
| FloatList ||
|-
| Font ||
|-
| Force || style="text-align:center;" | N
|-
| Frequency || style="text-align:center;" | Hz
|-
| HeatFlux || style="text-align:center;" | W/m^2|| {{Version|0.21}}
|-
| Integer ||
|-
| IntegerConstraint ||
|-
| IntegerList ||
|-
| IntegerSet ||
|-
| InverseArea || style="text-align:center;" | 1/m^2 || {{Version|0.21}}
|-
| InverseLength || style="text-align:center;" | 1/m || {{Version|0.21}}
|-
| InverseVolume || style="text-align:center;" | 1/m^3 || {{Version|0.21}}
|-
| KinematicViscosity || style="text-align:center;" | m^2/s || {{Version|0.21}}
|-
| Length || style="text-align:center;" | m
|-
| Link ||
|-
| LinkChild ||
|-
| LinkGlobal ||
|-
| LinkHidden ||
|-
| LinkList ||
|-
| LinkListChild ||
|-
| LinkListGlobal ||
|-
| LinkListHidden ||
|-
| LinkSub ||
|-
| LinkSubChild ||
|-
| LinkSubGlobal ||
|-
| LinkSubHidden ||
|-
| LinkSubList ||
|-
| LinkSubListChild ||
|-
| LinkSubListGlobal ||
|-
| LinkSubListHidden ||
|-
| LuminousIntensity || style="text-align:center;" | cd || {{Version|0.21}}
|-
| MagneticFieldStrength || style="text-align:center;" | A/m || {{Version|0.21}}
|-
| MagneticFlux || style="text-align:center;" | Wb or V*s || {{Version|0.21}}
|-
| MagneticFluxDensity || style="text-align:center;" | T || {{Version|0.21}}
|-
| Magnetization || style="text-align:center;" | A/m || {{Version|0.21}}
|-
| Map ||
|-
| Mass || style="text-align:center;" | kg || {{Version|0.21}}
|-
| Material ||
|-
| MaterialList ||
|-
| Matrix ||
|-
| PartShape || || a Part property, is accessed as</br>{{incode|Part::PropertyPartShape}}
|-
| Path ||
|-
| Percent ||
|-
| PersistentObject ||
|-
| Placement ||
|-
| PlacementLink ||
|-
| PlacementList ||
|-
| Position ||
|-
| Power || style="text-align:center;" | W || {{Version|0.21}}
|-
| Precision ||
|-
| Pressure || style="text-align:center;" | Pa
|-
| PythonObject ||
|-
| Quantity ||
|-
| QuantityConstraint ||
|-
| Rotation ||
|-
| ShearModulus || style="text-align:center;" | Pa || {{Version|0.21}}
|-
| SpecificEnergy || style="text-align:center;" | m^2/s^2 or J/kg || {{Version|0.21}}
|-
| SpecificHeat || style="text-align:center;" | J/kg/K || {{Version|0.21}}
|-
| Speed || style="text-align:center;" | m/s
|-
| Stiffness || style="text-align:center;" | m/s^2
|-
| Stress || style="text-align:center;" | Pa || {{Version|0.21}}
|-
| String ||
|-
| StringList ||
|-
| Temperature || style="text-align:center;" | K || {{Version|0.21}}
|-
| ThermalConductivity || style="text-align:center;" | W/m/K || {{Version|0.21}}
|-
| ThermalExpansionCoefficient || style="text-align:center;" | 1/K || {{Version|0.21}}
|-
| ThermalTransferCoefficient || style="text-align:center;" | W/m^2/K || {{Version|0.21}}
|-
| Time || style="text-align:center;" | s || {{Version|0.21}}
|-
| UltimateTensileStrength || style="text-align:center;" | Pa || {{Version|0.21}}
|-
| UUID ||
|-
| VacuumPermittivity || style="text-align:center;" | s^4*A^2 / (m^3*kg)
|-
| Vector ||
|-
| VectorDistance ||
|-
| VectorList ||
|-
| Velocity || style="text-align:center;" | m/s || {{Version|0.21}}
|-
| Volume || style="text-align:center;" | l or m^3
|-
| VolumeFlowRate || style="text-align:center;" | l/s or m^3/s || {{Version|0.21}}
|-
| VolumetricThermalExpansionCoefficient || style="text-align:center;" | 1/K || {{Version|0.21}}
|-
| Work || style="text-align:center;" | J || {{Version|0.21}}
|-
| XLink ||
|-
| XLinkList ||
|-
| XLinkSub ||
|-
| XLinkSubList ||
|-
| YieldStrength || style="text-align:center;" | Pa || {{Version|0.21}}
|-
| YoungsModulus || style="text-align:center;" | Pa || {{Version|0.21}}
|}
<translate>
<translate>


<!--T:10-->
Internally, the property name is prefixed with {{incode|App::Property}}:
Internally, the property name is prefixed with {{incode|App::Property}}:
</translate>
</translate>
Line 61: Line 259:
<translate>
<translate>


<!--T:11-->
== Scripting ==
Remember that these are property {{Emphasis|types}}. A single object may have many properties of the same type, but with different names.


<!--T:12-->
{{Emphasis|See also:}} [[FreeCAD Scripting Basics|FreeCAD scripting basics]]
For example:

</translate>
{{Code|code=
obj.addProperty("App::PropertyFloat", "Length")
obj.addProperty("App::PropertyFloat", "Width")
obj.addProperty("App::PropertyFloat", "Height")
}}
<translate>

<!--T:13-->
This indicates an object with three properties of type "Float", named "Length", "Width", and "Height", respectively.

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

<!--T:15-->
{{Emphasis|See also:}} [[FreeCAD_Scripting_Basics|FreeCAD scripting basics]]


<!--T:16-->
A [[scripted objects|scripted object]] is created first, and then properties are assigned.
A [[Scripted_objects|scripted object]] is created first, and then properties are assigned.
</translate>
</translate>
{{Code|code=
{{Code|code=
Line 75: Line 292:
<translate>
<translate>


<!--T:17-->
In general, {{Emphasis|Data}} properties are assigned by using the document's {{incode|addProperty()}} method. On the other hand, {{Emphasis|View}} properties are normally provided automatically by the parent object from which the scripted object is derived.
In general, {{Emphasis|Data}} properties are assigned by using the object's {{incode|addProperty()}} method. On the other hand, {{Emphasis|View}} properties are normally provided automatically by the parent object from which the scripted object is derived.


<!--T:18-->
For example:
For example:
* Deriving from {{incode|App::FeaturePython}} provides only 4 {{Emphasis|View}} properties: Display Mode, On Top When Selected, Show In Tree, and Visibility.
* Deriving from {{incode|App::FeaturePython}} provides only 4 {{Emphasis|View}} properties: "Display Mode", "On Top When Selected", "Show In Tree", and "Visibility".
* Deriving from {{incode|Part::Feature}} provides 17 {{Emphasis|View}} properties: the previous four, but also Angular Deflection, Bounding Box, Deviation, Draw Style, Lighting, Line Color, Line Width, Point Color, Point Size, Selectable, Selection Style, Shape Color, and Transparency.
* Deriving from {{incode|Part::Feature}} provides 17 {{Emphasis|View}} properties: the previous four, plus "Angular Deflection", "Bounding Box", "Deviation", "Draw Style", "Lighting", "Line Color", "Line Width", "Point Color", "Point Size", "Selectable", "Selection Style", "Shape Color", and "Transparency".


<!--T:19-->
Nevertheless, {{Emphasis|View}} properties can also be assigned using the view provider object's {{incode|addProperty()}} method.


</translate>
<!--T:2-->
{{Code|code=
{{docnav|Interface Customization|Workbenches}}
obj.ViewObject.addProperty("App::PropertyBool", "SuperVisibility", "Base", "Make the object glow")
}}
<translate>


<!--T:3-->
== Source code == <!--T:20-->

{{Userdocnavi}}
<!--T:21-->
In the source code, properties are located in various {{FileName|src/App/Property*}} files.

<!--T:22-->
They are imported and initialized in {{incode|[https://github.com/FreeCAD/FreeCAD/blob/9c27f1078e5ec516fe882aac1a27f5c6c6174554/src/App/Application.cpp#L1681-L1758 src/App/Application.cpp]}}.

</translate>
{{Code|lang=cpp|code=
#include "Property.h"
#include "PropertyContainer.h"
#include "PropertyUnits.h"
#include "PropertyFile.h"
#include "PropertyLinks.h"
#include "PropertyPythonObject.h"
#include "PropertyExpressionEngine.h"
}}
<translate>


<!--T:7-->
[[Category:Base]]


</translate>
</translate>
{{Powerdocnavi{{#translation:}}}}
{{clear}}
[[Category:Developer Documentation{{#translation:}}]]
[[Category:Python Code{{#translation:}}]]

Latest revision as of 16:25, 20 May 2023

Introduction

A property is a piece of information like a number or a text string that is attached to a FreeCAD document or an object in a document. Public properties can be viewed and modified in the Property editor.

Properties play a very important role in FreeCAD. As objects in FreeCAD are "parametric", this means that their behavior is defined by their properties, and how these properties are used as input for their class methods. See also FeaturePython Custom Properties and PropertyLink: InList and OutList

All property types

Custom scripted objects can use any of the property types defined in the base system:

Name Unit (if any) Remark
Acceleration m/s^2
AmountOfSubstance mol
Angle °
Area m^2
Bool
BoolList
Color
ColorList
CurrentDensity A/m^2 introduced in version 0.21
Density kg/m^3
Direction
DissipationRate m^2/s^3 introduced in version 0.21
Distance m
DynamicViscosity Pa*s introduced in version 0.21
ElectricalCapacitance F introduced in version 0.21
ElectricalConductance S introduced in version 0.21
ElectricalConductivity S/m introduced in version 0.21
ElectricalInductance H introduced in version 0.21
ElectricalResistance Ohm introduced in version 0.21
ElectricCharge C introduced in version 0.21
ElectricCurrent A introduced in version 0.21
ElectricPotential V introduced in version 0.20
Enumeration
ExpressionEngine
File
FileIncluded
Float
FloatConstraint
FloatList
Font
Force N
Frequency Hz
HeatFlux W/m^2 introduced in version 0.21
Integer
IntegerConstraint
IntegerList
IntegerSet
InverseArea 1/m^2 introduced in version 0.21
InverseLength 1/m introduced in version 0.21
InverseVolume 1/m^3 introduced in version 0.21
KinematicViscosity m^2/s introduced in version 0.21
Length m
Link
LinkChild
LinkGlobal
LinkHidden
LinkList
LinkListChild
LinkListGlobal
LinkListHidden
LinkSub
LinkSubChild
LinkSubGlobal
LinkSubHidden
LinkSubList
LinkSubListChild
LinkSubListGlobal
LinkSubListHidden
LuminousIntensity cd introduced in version 0.21
MagneticFieldStrength A/m introduced in version 0.21
MagneticFlux Wb or V*s introduced in version 0.21
MagneticFluxDensity T introduced in version 0.21
Magnetization A/m introduced in version 0.21
Map
Mass kg introduced in version 0.21
Material
MaterialList
Matrix
PartShape a Part property, is accessed as
Part::PropertyPartShape
Path
Percent
PersistentObject
Placement
PlacementLink
PlacementList
Position
Power W introduced in version 0.21
Precision
Pressure Pa
PythonObject
Quantity
QuantityConstraint
Rotation
ShearModulus Pa introduced in version 0.21
SpecificEnergy m^2/s^2 or J/kg introduced in version 0.21
SpecificHeat J/kg/K introduced in version 0.21
Speed m/s
Stiffness m/s^2
Stress Pa introduced in version 0.21
String
StringList
Temperature K introduced in version 0.21
ThermalConductivity W/m/K introduced in version 0.21
ThermalExpansionCoefficient 1/K introduced in version 0.21
ThermalTransferCoefficient W/m^2/K introduced in version 0.21
Time s introduced in version 0.21
UltimateTensileStrength Pa introduced in version 0.21
UUID
VacuumPermittivity s^4*A^2 / (m^3*kg)
Vector
VectorDistance
VectorList
Velocity m/s introduced in version 0.21
Volume l or m^3
VolumeFlowRate l/s or m^3/s introduced in version 0.21
VolumetricThermalExpansionCoefficient 1/K introduced in version 0.21
Work J introduced in version 0.21
XLink
XLinkList
XLinkSub
XLinkSubList
YieldStrength Pa introduced in version 0.21
YoungsModulus Pa introduced in version 0.21

Internally, the property name is prefixed with App::Property:

App::PropertyBool
App::PropertyFloat
App::PropertyFloatList
...

Remember that these are property types. A single object may have many properties of the same type, but with different names.

For example:

obj.addProperty("App::PropertyFloat", "Length")
obj.addProperty("App::PropertyFloat", "Width")
obj.addProperty("App::PropertyFloat", "Height")

This indicates an object with three properties of type "Float", named "Length", "Width", and "Height", respectively.

Scripting

See also: FreeCAD scripting basics

A scripted object is created first, and then properties are assigned.

obj = App.ActiveDocument.addObject("Part::Feature", "CustomObject")

obj.addProperty("App::PropertyFloat", "Velocity", "Parameter", "Body speed")
obj.addProperty("App::PropertyBool", "VelocityEnabled", "Parameter", "Enable body speed")

In general, Data properties are assigned by using the object's addProperty() method. On the other hand, View properties are normally provided automatically by the parent object from which the scripted object is derived.

For example:

  • Deriving from App::FeaturePython provides only 4 View properties: "Display Mode", "On Top When Selected", "Show In Tree", and "Visibility".
  • Deriving from Part::Feature provides 17 View properties: the previous four, plus "Angular Deflection", "Bounding Box", "Deviation", "Draw Style", "Lighting", "Line Color", "Line Width", "Point Color", "Point Size", "Selectable", "Selection Style", "Shape Color", and "Transparency".

Nevertheless, View properties can also be assigned using the view provider object's addProperty() method.

obj.ViewObject.addProperty("App::PropertyBool", "SuperVisibility", "Base", "Make the object glow")

Source code

In the source code, properties are located in various src/App/Property* files.

They are imported and initialized in src/App/Application.cpp.

#include "Property.h"
#include "PropertyContainer.h"
#include "PropertyUnits.h"
#include "PropertyFile.h"
#include "PropertyLinks.h"
#include "PropertyPythonObject.h"
#include "PropertyExpressionEngine.h"