Expressions/it: Difference between revisions
Renatorivo (talk | contribs) (Created page with "Quindi creare gli ulteriori documenti in cui si desidera aggiungere espressioni. Supponendo di aver chiamato il documento master "master" è possibile accedervi con un alias c...") |
Renatorivo (talk | contribs) No edit summary |
||
(47 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<languages/> |
|||
{{Version|0.16}} |
|||
<div style="float:right; clean:both; margin-left:0.5em;">__TOC__</div> |
|||
==Descrizione== |
|||
È possibile definire le proprietà utilizzando espressioni matematiche. Nella GUI, gli spin box o i campi di input che sono legati alle proprietà contengono un'icona blu [[Image:Sketcher_Expressions.png|24px]]. Cliccando sull'icona, oppure digitando il segno di uguale (=), si porta in primo piano l'editor delle espressioni per quella particolare proprietà. |
|||
Una espressione di FreeCAD è un'espressione matematica che segue la notazione per gli operatori matematici standard e le funzioni come descritto in seguito. Inoltre, l'espressione può fare riferimento ad altre proprietà, e anche utilizzare le condizioni. I numeri di un'espressione possono opzionalmente essere collegati ad una unità di misura. |
|||
Numbers may use either a comma ',' or a decimal point '.' separating whole digits from decimals. |
|||
When the decimal marker is used, it ''must'' be followed by at least one digit. |
|||
Thus, the expressions '''1.+2.''' and '''1,+2,''' are invalid, but '''1.0 + 2.0''' and '''1,0 + 2,0''' are valid. |
|||
Gli operatori e le funzioni sono unit-aware (consapevoli delle unità), e richiedono combinazioni di unità valide, se sono fornite. Ad esempio, '''2mm + 4mm''' è un'espressione valida, mentre '''2mm + 4''' non lo è (il motivo di questo è che un'espressione come '''1in + 4''' molto probabilmente viene interpretata come '''1in + 4in''' da un umano, ma tutte le unità vengono convertite nel sistema SI interno, e il sistema non è in grado di indovinare questo). Queste [[#Unità|unità]] sono attualmente riconosciute. |
|||
You can use [[#Supported Constants|predefined constants]] and [[#Supported Functions|functions]]. |
|||
===Referencing objects=== |
|||
You can reference to an object by its {{incode|Name}} or by its {{incode|Label}}. In the case of a {{incode|Label}}, it must be enclosed in double {{incode|<<}} and {{incode|>>}} symbols, such as {{incode|<<Label>>}}. |
|||
You can reference any numerical property of this object. For example, to refer to a Cylinder's height, you may use {{incode|Cylinder.Height}} or {{incode|<<Long_name_of_cylinder>>.Height}}. |
|||
To reference list objects, the syntax is {{incode|object_name.list[list_index]}}. If you want for example reference a constraint in a sketch, hover with the mouse over this constraint and look in the footer of FreeCAD's main window. Assuming you see there ''Sketch_name.Constraint17'', then you reference it this way: '''Sketch_name.Constraints[16]''' (The index starts with 0, therefore constraint 17 has the index 16.) If you are in the same sketch you can omit its name and just use '''Constraints[16]'''. |
|||
For more info about referencing objects, see [[#Reference To CAD-Data|this section]]. |
|||
==Supported Operators== |
|||
The following operators are supported: |
|||
Ora è possibile definire le proprietà utilizzando espressioni matematiche. Nella GUI, gli spin box o i campi di input che sono legati alle proprietà contengono un'icona blu [[Image:Sketcher_Expressions.png|24px]]. Cliccando sull'icona, oppure digitando il segno di uguale (=), si porta in primo piano l'editor delle espressioni per quella particolare proprietà. |
|||
{| class="wikitable float-right mw-collapsible mw-uncollapsed" |
|||
!style="width: 33%;"|Operator |
|||
!style="width: 66%;"|Description |
|||
|- |
|||
| + |
|||
| [https://en.wikipedia.org/wiki/Addition Addition] |
|||
|- |
|||
| - |
|||
| [https://en.wikipedia.org/wiki/Subtraction Subtraction] |
|||
|- |
|||
| * |
|||
| [https://en.wikipedia.org/wiki/Multiplication Multiplication] |
|||
|- |
|||
| / |
|||
| [https://en.wikipedia.org/wiki/Division_(mathematics) Division] |
|||
|- |
|||
| ^ |
|||
| [https://en.wikipedia.org/wiki/Exponentiation Exponentiation] |
|||
|} |
|||
== Costanti supportate == |
|||
Una espressione di FreeCAD è un'espressione matematica che segue la normale notazione per gli operatori matematici standard (+, -, * e /) e le funzioni come descritto in seguito. Inoltre, l'espressione può fare riferimento ad altre proprietà, e anche utilizzare le condizioni. I numeri di un'espressione possono opzionalmente essere collegati ad una unità di misura. |
|||
<div class="mw-translate-fuzzy"> |
|||
Gli operatori e le funzioni sono unit-aware (consapevoli delle unità), e richiedono combinazioni di unità valide, se sono fornite. Ad esempio, 2mm + 4mm è un'espressione valida, mentre 2mm + 4 non lo è (il motivo di questo è che un'espressione come 1in + 4 molto probabilmente viene interpretata come 1in + 4in da un umano, ma tutte le unità vengono convertite nel sistema SI interno, e il sistema non è in grado di indovinare questo). |
|||
{{APIFunction |abs|x| Absolute value | value <nowiki> >= 0 </nowiki> }} |
|||
{{APIFunction |acos|x| Arc cosine; <nowiki> -1 <= x <= 1 </nowiki> | acos(x) }} |
|||
{{APIFunction |asin|x| Arc sine; <nowiki> -1 <= x <= 1 </nowiki> | asin(x) }} |
|||
{{APIFunction |atan|x| Arc tangent | atan(x) }} |
|||
{{APIFunction |atan2|y, x| Arc tangent of y / x; | atan2(y,x) }} |
|||
{{APIFunction |ceil|x| Ceiling | The smallest integer value greater than or equal to x {{Version|0.16}} }} |
|||
{{APIFunction |cos|angle| Cosine; angle is in degrees (any value) | <nowiki> -1 <= cos(x) <= 1 </nowiki> }} |
|||
{{APIFunction |cosh|x| Hyperbolic cosine of x | cosh(x) }} |
|||
{{APIFunction |exp|y| Natural exponent | e<sup> y</sup> }} |
|||
{{APIFunction |floor|x| Floor | The largest integer value less than or equal to x {{Version|0.16}} }} |
|||
{{APIFunction |log|x| Natural logarithm | log<sub>e</sub> x }} |
|||
{{APIFunction |log10|x| Logarithm base 10 | log<sub>10</sub> x }} |
|||
{{APIFunction |mod|x, y| Remainder x/y | Remainder after dividing x by y }} |
|||
{{APIFunction |pow|x, y| Power function| x<sup> y</sup> }} |
|||
{{APIFunction |round|x| | x rounded to the nearest integer {{Version|0.16}} }} |
|||
{{APIFunction |sin|angle| Cosine; angle in degrees (any value) | <nowiki> -1 <= sin(x) <= 1 </nowiki> }} |
|||
{{APIFunction |sinh|x| Hyperbolic sine of x | sinh(x) }} |
|||
{{APIFunction |sqrt|x| Square root; <nowiki> x >= 0 </nowiki> | Square root of x }} |
|||
{{APIFunction |tan|angle| Tangent; angle in degrees (any value) | tan(angle) }} |
|||
{{APIFunction |tanh|x| Hyperbolic tangent of x | tanh(x) }} |
|||
{{APIFunction |trunc|x| Truncate | x truncated to the nearest integer {{Version|0.16}} }} |
|||
</div> |
|||
== Funzioni Supportate == |
== Funzioni Supportate == |
||
=== Funzioni matematiche generali === |
|||
Nelle espressioni, sono supportate le seguenti funzioni, usando uno o due argomenti: abs, acos, asin, atan, atan2, cos, cosh, exp, log, log10, mod, pow, sin, sinh, sqrt, tan, tanh, ceil, floor, trunc, round. |
|||
Le funzioni matematiche elencate di seguito sono disponibili. |
|||
Le funzioni trigonometriche utilizzano i gradi come unità di default; fornire "rad" se si desidera che utilizzino i radianti. |
|||
Multiple arguments to a function may be separated by either a semicolon ';' or a comma <em>followed by a space</em> ', '. In the latter case, the comma is converted to a semicolon after entry. When a semicolon is used, no trailing space is necessary. |
|||
Le costanti pi greco ed e sono predefinite |
|||
[https://en.wikipedia.org/wiki/Trigonometric_functions Trigonometric functions] use degree as their default unit. For radian measure, add '''rad''' following the <em>first</em> value in an expression. So e.g. '''cos(45)''' is the same as '''cos(pi rad / 4)'''.<br/> |
|||
L'istruzione condizionale funziona così: = condition ? resultTrue : resultFalse |
|||
These trigonometric functions are supported: |
|||
{| class="wikitable float-right mw-collapsible mw-collapsed" |
|||
!style="width: 33%;"|Function |
|||
!style="width: 33%;"|Description |
|||
!style="width: 33%;"|Value range |
|||
|- |
|||
| acos(x) |
|||
| [https://en.wikipedia.org/wiki/Inverse_trigonometric_functions#Basic_properties Arc cosine] |
|||
| -1 <= x <= 1 |
|||
|- |
|||
| asin(x) |
|||
| [https://en.wikipedia.org/wiki/Inverse_trigonometric_functions#Basic_properties Arc sine] |
|||
| -1 <= x <= 1 |
|||
|- |
|||
| atan(x) |
|||
| [https://en.wikipedia.org/wiki/Inverse_trigonometric_functions#Basic_properties Arc tangent] |
|||
| all |
|||
|- |
|||
| atan2(x, y) |
|||
| [https://en.wikipedia.org/wiki/Inverse_trigonometric_functions#Basic_properties Arc tangent] of ''x/y'' |
|||
| all, except y = 0 |
|||
|- |
|||
| cos(x) |
|||
| [https://en.wikipedia.org/wiki/Trigonometric_functions#Right-angled_triangle_definitions Cosine] |
|||
| all |
|||
|- |
|||
| cosh(x) |
|||
| [https://en.wikipedia.org/wiki/Hyperbolic_function#Trigonometric_definitions Hyperbolic cosine] |
|||
| all |
|||
|- |
|||
| sin(x) |
|||
| [https://en.wikipedia.org/wiki/Trigonometric_functions#Right-angled_triangle_definitions Sine] |
|||
| all |
|||
|- |
|||
| sinh(x) |
|||
| [https://en.wikipedia.org/wiki/Hyperbolic_function#Trigonometric_definitions Hyperbolic sine] |
|||
| all |
|||
|- |
|||
| tan(x) |
|||
| [https://en.wikipedia.org/wiki/Trigonometric_functions#Right-angled_triangle_definitions Tangent] |
|||
| all, except of x = n·90 with n = integer |
|||
|- |
|||
| tanh(x) |
|||
| [https://en.wikipedia.org/wiki/Hyperbolic_function#Trigonometric_definitions Hyperbolic tangent] |
|||
| all |
|||
|} |
|||
These functions for exponentiation and logarithmization are supported: |
|||
La condizione è definita come un'espressione che restituisce 0 (per false) o non-zero per true. Sono definiti i seguenti operatori di confronto: ==, !=, >, <, >=, and <=. |
|||
{| class="wikitable float-right mw-collapsible mw-collapsed" |
|||
!style="width: 33%;"|Function |
|||
!style="width: 33%;"|Description |
|||
!style="width: 33%;"|Value range |
|||
|- |
|||
| exp(x) |
|||
| [https://en.wikipedia.org/wiki/Exponential_function#Formal_definition Exponential function] |
|||
| all |
|||
|- |
|||
| log(x) |
|||
| [https://en.wikipedia.org/wiki/Natural_logarithm Natural logarithm] |
|||
| x > 0 |
|||
|- |
|||
| log10(x) |
|||
| [https://en.wikipedia.org/wiki/Common_logarithm Common logarithm] |
|||
| x > 0 |
|||
|- |
|||
| pow(x, y) |
|||
| [https://en.wikipedia.org/wiki/Exponentiation Exponentiation] |
|||
| all |
|||
|- |
|||
| sqrt(x) |
|||
| [https://en.wikipedia.org/wiki/Square_root Square root] |
|||
| x >= 0 |
|||
|} |
|||
These functions for rounding, truncation and remainder are supported: |
|||
Le formule sono scritte in questo modo: 2 * Length, dove Length è una proprietà contenuta nell'oggetto dell'espressione. |
|||
{| class="wikitable float-right mw-collapsible mw-collapsed" |
|||
!style="width: 20%;"|Function |
|||
!style="width: 55%;"|Description |
|||
!style="width: 25%;"|Value range |
|||
|- |
|||
| abs(x) |
|||
| [https://en.wikipedia.org/wiki/Absolute_value Absolute value] |
|||
| all |
|||
|- |
|||
| ceil(x) |
|||
| [https://en.wikipedia.org/wiki/Floor_and_ceiling_functions Ceiling function] smallest integer value greater than or equal to x |
|||
| all |
|||
|- |
|||
| floor(x) |
|||
| [https://en.wikipedia.org/wiki/Floor_and_ceiling_functions Floor function], largest integer value less than or equal to x |
|||
| all |
|||
|- |
|||
| mod(x, y) |
|||
| [https://en.wikipedia.org/wiki/Remainder Remainder] after dividing ''x'' by ''y'' |
|||
| all, except y = 0 |
|||
|- |
|||
| round(x) |
|||
| [https://en.wikipedia.org/wiki/Rounding Rounding] to the nearest integer |
|||
| all |
|||
|- |
|||
| trunc(x) |
|||
| [https://en.wikipedia.org/wiki/Truncation Truncation] to the nearest integer |
|||
| all |
|||
|} |
|||
<div class="mw-translate-fuzzy"> |
|||
=== Statistica / Funzioni di aggregazione === |
|||
Le funzioni di aggregazione elencate di seguito sono supportate. |
|||
Le funzioni di aggregazione accettano uno o più argomenti, separati da un punto e virgola ';' o una virgola e uno spazio ", ". |
|||
Gli argomenti possono includere riferimenti a celle di un foglio di calcolo; i riferimenti alla cella sono costituiti dalla lettera di riga (Maiuscola) seguita dal numero di colonna. |
|||
Gli argomenti possono includere intervalli di celle (due riferimenti di cella separati da due punti). |
|||
Esempio: ''average(B1:B8)'' |
|||
</div> |
|||
<div class="mw-translate-fuzzy"> |
|||
{{APIFunction |average|x y| Average of values in cells x through y | sum(x, y) / count(x, y) }} |
|||
{{APIFunction |count|x y| Number of cells from x through y | The number of cells from x through y, inclusive }} |
|||
{{APIFunction |max|x y| Maximum value in cells x through y | Maximum value }} |
|||
{{APIFunction |min|x y| Minimum value in cells x through y | Minimum value }} |
|||
{{APIFunction |stddev|x y| Standard deviation of values in cells x through y | Standard deviation }} |
|||
{{APIFunction |sum|x y| Sum of values in cells x through y | Sum }} |
|||
</div> |
|||
== Espressioni condizionali == |
|||
<div class="mw-translate-fuzzy"> |
|||
Le espressioni condizionali sono nella forma ''condition ? resultTrue : resultFalse'' |
|||
</div> |
|||
The following [https://en.wikipedia.org/wiki/Relational_operator#Standard_relational_operators relational operators] are defined: |
|||
{| class="wikitable float-right mw-collapsible mw-uncollapsed" |
|||
!style="width: 33%;"|Unit |
|||
!style="width: 66%;"|Description |
|||
|- |
|||
| == |
|||
| equal to |
|||
|- |
|||
| != |
|||
| not equal to |
|||
|- |
|||
| > |
|||
| greater than |
|||
|- |
|||
| < |
|||
| less than |
|||
|- |
|||
| >= |
|||
| greater than or equal to |
|||
|- |
|||
| <= |
|||
| less than or equal to |
|||
|} |
|||
==Unità== |
|||
Units can directly be used in expressions. The parser connects them to the previous value. So ''''2mm'''' or ''''2 mm'''' is valid while '''' mm'''' is invalid because there is no preceding value. |
|||
All values must have a unit. Therefore you must in general use a unit for values in spreadsheets.<br/> |
|||
In some cases it works even without a unit, for example if you have e.g. in spreadsheet cell B1 just the number ''1.5'' and refer to it for a pad height. This only works because the pad height predefines the unit ''mm'' that is used if no unit is given. It will nevertheless fail if you use for the pad height e.g. '''Sketch1.Constraints.Width - Spreadsheet.B1''' because ''Sketch1.Constraints.Width'' has a unit and ''Spreadsheet.B1'' has not. |
|||
Units with exponents can directly be entered. So e.g. '''mm^3''' will be recognized as mm³ and '''m^3''' will be recognized as m³. |
|||
<div class="mw-translate-fuzzy"> |
|||
Le funzioni trigonometriche usano i gradi come unità predefinita. |
|||
Per le misurazioni che utilizzano il radiante, aggiungere rad dopo il primo valore angolare nell'espressione. Esempio: cos(45) è equivalente a cos(pi rad/4). |
|||
</div> |
|||
The following units are recognized by the expression parser: |
|||
Amount of substance: |
|||
{| class="wikitable float-right mw-collapsible mw-collapsed" |
|||
!style="width: 33%;"|Unit |
|||
!style="width: 66%;"|Description |
|||
|- |
|||
| mol |
|||
| [https://en.wikipedia.org/wiki/Mole_(unit) Mole] |
|||
|} |
|||
Angle: |
|||
{| class="wikitable float-right mw-collapsible mw-collapsed" |
|||
!style="width: 33%;"|Unit |
|||
!style="width: 66%;"|Description |
|||
|- |
|||
| ° |
|||
| [https://en.wikipedia.org/wiki/Degree_(angle) Degree]; alternative to the unit ''deg'' |
|||
|- |
|||
| deg |
|||
| [https://en.wikipedia.org/wiki/Degree_(angle) Degree]; alternative to the unit ''°'' |
|||
|- |
|||
| rad |
|||
| [https://en.wikipedia.org/wiki/Radian Radian] |
|||
|- |
|||
| gon |
|||
| [https://en.wikipedia.org/wiki/Gon_(unit) Gradian] |
|||
|- |
|||
| S |
|||
| [https://en.wikipedia.org/wiki/Minute_and_second_of_arc Second of arc] |
|||
|- |
|||
| ″ |
|||
| [https://en.wikipedia.org/wiki/Minute_and_second_of_arc Second of arc]; alternative to the unit ''S'' |
|||
|- |
|||
| M |
|||
| [https://en.wikipedia.org/wiki/Minute_and_second_of_arc Minute of arc] |
|||
|- |
|||
| ′ |
|||
| [https://en.wikipedia.org/wiki/Minute_and_second_of_arc Minute of arc]; alternative to the unit ''M'' |
|||
|} |
|||
Current: |
|||
{| class="wikitable float-right mw-collapsible mw-collapsed" |
|||
!style="width: 33%;"|Unit |
|||
!style="width: 66%;"|Description |
|||
|- |
|||
| mA |
|||
| Milli[https://en.wikipedia.org/wiki/Ampere ampere] |
|||
|- |
|||
| A |
|||
| [https://en.wikipedia.org/wiki/Ampere Ampere] |
|||
|- |
|||
| kA |
|||
| Kilo[https://en.wikipedia.org/wiki/Ampere ampere] |
|||
|- |
|||
| MA |
|||
| Mega[https://en.wikipedia.org/wiki/Ampere ampere] |
|||
|} |
|||
Energy / Work: |
|||
{| class="wikitable float-right mw-collapsible mw-collapsed" |
|||
!style="width: 33%;"|Unit |
|||
!style="width: 66%;"|Description |
|||
|- |
|||
| J |
|||
| [https://en.wikipedia.org/wiki/Joule Joule] |
|||
|- |
|||
| Ws |
|||
| [https://en.wikipedia.org/wiki/Joule#Watt_second Watt second]; alternative to the unit ''Joule'' |
|||
|- |
|||
| VAs |
|||
| [https://en.wikipedia.org/wiki/Joule Volt-ampere-second]; alternative to the unit ''Joule'' |
|||
|- |
|||
| CV |
|||
| [https://en.wikipedia.org/wiki/Joule Coulomb·Volt]; alternative to the unit ''Joule'' |
|||
|} |
|||
Force: |
|||
{| class="wikitable float-right mw-collapsible mw-collapsed" |
|||
!style="width: 33%;"|Unit |
|||
!style="width: 66%;"|Description |
|||
|- |
|||
| mN |
|||
| Milli[https://en.wikipedia.org/wiki/Newton_(unit) newton] |
|||
|- |
|||
| N |
|||
| [https://en.wikipedia.org/wiki/Newton_(unit) Newton] |
|||
|- |
|||
| kN |
|||
| Kilo[https://en.wikipedia.org/wiki/Newton_(unit) newton] |
|||
|- |
|||
| MN |
|||
| Mega[https://en.wikipedia.org/wiki/Newton_(unit) newton] |
|||
|- |
|||
| lbf |
|||
| [https://en.wikipedia.org/wiki/Pound_(force) Pound of force] |
|||
|} |
|||
Length: |
|||
{| class="wikitable float-right mw-collapsible mw-collapsed" |
|||
!style="width: 33%;"|Unit |
|||
!style="width: 66%;"|Description |
|||
|- |
|||
| nm |
|||
| Nano[https://en.wikipedia.org/wiki/Metre meter] |
|||
|- |
|||
| um |
|||
| Micro[https://en.wikipedia.org/wiki/Metre meter]; alternative to the unit ''µm'' |
|||
|- |
|||
| µm |
|||
| Micro[https://en.wikipedia.org/wiki/Metre meter]; alternative to the unit ''mu'' |
|||
|- |
|||
| mm |
|||
| Milli[https://en.wikipedia.org/wiki/Metre meter] |
|||
|- |
|||
| cm |
|||
| Centi[https://en.wikipedia.org/wiki/Metre meter] |
|||
|- |
|||
| mm |
|||
| Milli[https://en.wikipedia.org/wiki/Metre meter] |
|||
|- |
|||
| dm |
|||
| Deci[https://en.wikipedia.org/wiki/Metre meter] |
|||
|- |
|||
| m |
|||
| [https://en.wikipedia.org/wiki/Metre Meter] |
|||
|- |
|||
| km |
|||
| Kilo[https://en.wikipedia.org/wiki/Metre meter] |
|||
|- |
|||
| mil |
|||
| [https://en.wikipedia.org/wiki/Thousandth_of_an_inch Thousandth of an inch]; alternative to the unit ''thou'' |
|||
|- |
|||
| thou |
|||
| [https://en.wikipedia.org/wiki/Thousandth_of_an_inch Thousandth of an inch]; alternative to the unit ''mil'' |
|||
|- |
|||
| in |
|||
| [https://en.wikipedia.org/wiki/Inch Inch] |
|||
|- |
|||
| ft |
|||
| [https://en.wikipedia.org/wiki/Foot_(unit) Foot]; alternative to the unit ' |
|||
|- |
|||
| ' |
|||
| [https://en.wikipedia.org/wiki/Foot_(unit) Foot]; alternative to the unit ''ft'' |
|||
|- |
|||
| yd |
|||
| [https://en.wikipedia.org/wiki/Yard Yard] |
|||
|- |
|||
| mi |
|||
| [https://en.wikipedia.org/wiki/Mile Mile] |
|||
|} |
|||
Luminous intensity: |
|||
{| class="wikitable float-right mw-collapsible mw-collapsed" |
|||
!style="width: 33%;"|Unit |
|||
!style="width: 66%;"|Description |
|||
|- |
|||
| cd |
|||
| [https://en.wikipedia.org/wiki/Candela Candela] |
|||
|} |
|||
Mass: |
|||
{| class="wikitable float-right mw-collapsible mw-collapsed" |
|||
!style="width: 33%;"|Unit |
|||
!style="width: 66%;"|Description |
|||
|- |
|||
| ug |
|||
| Micro[https://en.wikipedia.org/wiki/Gram gram]; alternative to the unit ''µg'' |
|||
|- |
|||
| µg |
|||
| Micro[https://en.wikipedia.org/wiki/Gram gram]; alternative to the unit ''ug'' |
|||
|- |
|||
| mg |
|||
| Milli[https://en.wikipedia.org/wiki/Gram gram] |
|||
|- |
|||
| g |
|||
| [https://en.wikipedia.org/wiki/Gram Gram] |
|||
|- |
|||
| kg |
|||
| Kilo[https://en.wikipedia.org/wiki/Gram gram] |
|||
|- |
|||
| t |
|||
| [https://en.wikipedia.org/wiki/Tonne Tonne] |
|||
|- |
|||
| oz |
|||
| [https://en.wikipedia.org/wiki/Ounce Ounce] |
|||
|- |
|||
| lb |
|||
| [https://en.wikipedia.org/wiki/Pound_(mass) Pound]; alternative to the unit ''lbm'' |
|||
|- |
|||
| lbm |
|||
| [https://en.wikipedia.org/wiki/Pound_(mass) Pound]; alternative to the unit ''lb'' |
|||
|- |
|||
| st |
|||
| [https://en.wikipedia.org/wiki/Stone_(weight) Stone] |
|||
|- |
|||
| cwt |
|||
| [https://en.wikipedia.org/wiki/Hundredweight Hundredweight] |
|||
|} |
|||
Power: |
|||
{| class="wikitable float-right mw-collapsible mw-collapsed" |
|||
!style="width: 33%;"|Unità |
|||
!style="width: 66%;"|Descrizione |
|||
|- |
|||
| W |
|||
| [https://en.wikipedia.org/wiki/Watt Watt] |
|||
|- |
|||
| VA |
|||
| [https://en.wikipedia.org/wiki/Volt-ampere Volt-ampere] |
|||
|} |
|||
Pressure: |
|||
{| class="wikitable float-right mw-collapsible mw-collapsed" |
|||
!style="width: 33%;"|Unit |
|||
!style="width: 66%;"|Description |
|||
|- |
|||
| Pa |
|||
| [https://en.wikipedia.org/wiki/Pascal_(unit) Pascal] |
|||
|- |
|||
| kPa |
|||
| Kilo[https://en.wikipedia.org/wiki/Pascal_(unit) pascal] |
|||
|- |
|||
| MPa |
|||
| Mega[https://en.wikipedia.org/wiki/Pascal_(unit) pascal] |
|||
|- |
|||
| GPa |
|||
| Giga[https://en.wikipedia.org/wiki/Pascal_(unit) pascal] |
|||
|- |
|||
| uTorr |
|||
| Micro[https://en.wikipedia.org/wiki/Torr torr]; alternative to the unit ''µTorr'' |
|||
|- |
|||
| µTorr |
|||
| Micro[https://en.wikipedia.org/wiki/Torr torr]; alternative to the unit ''uTorr'' |
|||
|- |
|||
| mTorr |
|||
| Milli[https://en.wikipedia.org/wiki/Torr torr] |
|||
|- |
|||
| Torr |
|||
| [https://en.wikipedia.org/wiki/Torr Torr] |
|||
|- |
|||
| psi |
|||
| [https://en.wikipedia.org/wiki/Pounds_per_square_inch Pound-force per square inch] |
|||
|- |
|||
| ksi |
|||
| Kilo[https://en.wikipedia.org/wiki/Pounds_per_square_inch pound-force per square inch] |
|||
|} |
|||
Temperature: |
|||
{| class="wikitable float-right mw-collapsible mw-collapsed" |
|||
!style="width: 33%;"|Unit |
|||
!style="width: 66%;"|Description |
|||
|- |
|||
| uK |
|||
| Micro[https://en.wikipedia.org/wiki/Kelvin kelvin]; alternative to the unit ''µK'' |
|||
|- |
|||
| µK |
|||
| Micro[https://en.wikipedia.org/wiki/Kelvin kelvin]; alternative to the unit ''uK'' |
|||
|- |
|||
| mK |
|||
| Milli[https://en.wikipedia.org/wiki/Kelvin kelvin] |
|||
|- |
|||
| K |
|||
| [https://en.wikipedia.org/wiki/Kelvin Kelvin] |
|||
|} |
|||
Time: |
|||
{| class="wikitable float-right mw-collapsible mw-collapsed" |
|||
!style="width: 33%;"|Unit |
|||
!style="width: 66%;"|Description |
|||
|- |
|||
| s |
|||
| [https://en.wikipedia.org/wiki/Second Second] |
|||
|- |
|||
| min |
|||
| [https://en.wikipedia.org/wiki/Minute Minute] |
|||
|- |
|||
| h |
|||
| [https://en.wikipedia.org/wiki/Hour Hour] |
|||
|} |
|||
Torque: |
|||
{| class="wikitable float-right mw-collapsible mw-collapsed" |
|||
!style="width: 33%;"|Unit |
|||
!style="width: 66%;"|Description |
|||
|- |
|||
| Nm |
|||
| [https://en.wikipedia.org/wiki/Newton_metre Newton metre] |
|||
|} |
|||
Volume: |
|||
{| class="wikitable float-right mw-collapsible mw-collapsed" |
|||
!style="width: 33%;"|Unit |
|||
!style="width: 66%;"|Description |
|||
|- |
|||
| l |
|||
| [https://en.wikipedia.org/wiki/Litre Liter] |
|||
|} |
|||
The following commonly used units are not yet supported: |
|||
{| class="wikitable float-right mw-collapsible mw-collapsed" |
|||
!style="width: 25%;"|Unit |
|||
!style="width: 50%;"|Description |
|||
!style="width: 25%;"|Alternative |
|||
|- |
|||
| C |
|||
| [https://en.wikipedia.org/wiki/Coulomb Coulomb] |
|||
| 1 A*s |
|||
|- |
|||
| Hz |
|||
| [https://en.wikipedia.org/wiki/Hertz Hertz] |
|||
| 1 /s |
|||
|- |
|||
| V |
|||
| [https://en.wikipedia.org/wiki/Volt Volt] |
|||
| 1 W/A |
|||
|- |
|||
| eV |
|||
| [https://en.wikipedia.org/wiki/Electronvolt Electronvolt] |
|||
| 1.602176634e-19 J |
|||
|- |
|||
| kWh |
|||
| [https://en.wikipedia.org/wiki/Kilowatt_hour Kilowatt hour] |
|||
| 3.6e6 J |
|||
|- |
|||
| bar |
|||
| [https://en.wikipedia.org/wiki/Bar_(unit) Bar] |
|||
| 100 kPa |
|||
|- |
|||
| T |
|||
| [https://en.wikipedia.org/wiki/Tesla_(unit) Tesla] |
|||
| 1 kg/s^2/A |
|||
|- |
|||
| F |
|||
| [https://en.wikipedia.org/wiki/Farad Farad] |
|||
| 1 s^4*A^2/m^2/kg |
|||
|- |
|||
| H |
|||
| [https://en.wikipedia.org/wiki/Henry_(unit) Henry] |
|||
| 1 kg*m^2/s^2/A^2 |
|||
|- |
|||
| u |
|||
| [https://en.wikipedia.org/wiki/Unified_atomic_mass_unit Atomic mass unit]; alternative to the unit 'Da' |
|||
| 1.66053906660e-27 kg |
|||
|- |
|||
| Da |
|||
| [https://en.wikipedia.org/wiki/Unified_atomic_mass_unit Dalton]; alternative to the unit 'u' |
|||
| 1.66053906660e-27 kg |
|||
|- |
|||
| cal |
|||
| [https://en.wikipedia.org/wiki/Calorie Calorie] |
|||
| 4.184 J |
|||
|- |
|||
| sr |
|||
| [https://en.wikipedia.org/wiki/Steradian Steradian] |
|||
| not directly |
|||
|- |
|||
| lm |
|||
| [https://en.wikipedia.org/wiki/Lumen_(unit) Lumen] |
|||
| not directly |
|||
|- |
|||
| lx |
|||
| [https://en.wikipedia.org/wiki/Lux Lux] |
|||
| not directly |
|||
|- |
|||
| Mpsi |
|||
| Mega[https://en.wikipedia.org/wiki/Pounds_per_square_inch pound-force per square inch] |
|||
| 1000 ksi |
|||
|} |
|||
== Riferimento ai dati CAD == |
== Riferimento ai dati CAD == |
||
In un'espressione è possibile utilizzare i dati |
In un'espressione è possibile utilizzare i dati del modello stesso. Per fare riferimento a una proprietà usare object.property. Se la proprietà è un composto di campi, è possibile accedere ai singoli campi come object.property.field. |
||
La tabella seguente mostra alcuni esempi: |
La tabella seguente mostra alcuni esempi: |
||
Line 45: | Line 646: | ||
|Etichetta del Cubo |
|Etichetta del Cubo |
||
|Cube.Label |
|Cube.Label |
||
|Stringa: |
|Stringa: Label |
||
|- |
|- |
||
|coordinata x del centro di massa del Cubo |
|coordinata x del centro di massa del Cubo |
||
Line 53: | Line 654: | ||
|Valore di un vincolo in uno schizzo |
|Valore di un vincolo in uno schizzo |
||
|Constraints.Width |
|Constraints.Width |
||
|Valore numerico del vincolo di nome 'Width' nello schizzo |
|Valore numerico del vincolo di nome 'Width' nello schizzo, se l'espressione è utilizzata nello schizzo stesso. |
||
|- |
|||
|Valore di un vincolo in uno schizzo |
|||
|MySketch.Constraints.Width |
|||
|Valore numerico del vincolo di nome 'Width' nello schizzo, se l'espressione è usata al di fuori dello schizzo. |
|||
|- |
|- |
||
|Valore di un alias in spreadsheet |
|Valore di un alias in spreadsheet |
||
Line 66: | Line 671: | ||
== Variabili globali nell'ambito del documento == |
== Variabili globali nell'ambito del documento == |
||
Al momento in FreeCAD non esiste il concetto di variabili globali. Invece, utilizzando l'ambiente Spreadsheet, si possono definire delle variabili arbitrarie come celle in un foglio di calcolo, e poi assegnare loro un nome utilizzando la proprietà alias della cella (tasto destro del mouse sulla cella). Dopo si può accedere alla variabile da qualsiasi espressione, come per qualsiasi altra proprietà di un oggetto. |
Al momento in FreeCAD non esiste il concetto di variabili globali. Invece, utilizzando l'ambiente [[Spreadsheet Workbench/it|Spreadsheet]], si possono definire delle variabili arbitrarie come celle in un foglio di calcolo, e poi assegnare loro un nome utilizzando la proprietà alias della cella (tasto destro del mouse sulla cella). Dopo si può accedere alla variabile da qualsiasi espressione, come per qualsiasi altra proprietà di un oggetto. |
||
== Riferimenti incrociati nel documento == |
== Riferimenti incrociati nel documento == |
||
<div class="mw-translate-fuzzy"> |
|||
Un documento può contenere un foglio di calcolo in cui i valori sono riferiti ad altri documenti. |
|||
In un documento è possibile fare riferimento a un foglio di calcolo contenuto in un altro documento. |
|||
</div> |
|||
È possibile utilizzare il nome di un documento per fare riferimento ad esso da altri documenti. Quando si salva un documento per la prima volta, si sceglie un nome per il file; questo di solito è diverso dal default iniziale "Unnamed1" (o il suo equivalente tradotto). Per evitare la perdita dei collegamenti quando il documento master viene rinominato al momento del salvataggio, si consiglia di creare prima il documento master, creare un foglio di calcolo al suo interno e salvarlo. Successivamente è ancora possibile apportare modifiche e salvare il file, ma non si deve rinominarlo. |
|||
<div class="mw-translate-fuzzy"> |
|||
Quindi creare gli ulteriori documenti in cui si desidera aggiungere espressioni. Supponendo di aver chiamato il documento master "master" è possibile accedervi con un alias come questo: master#Spreadsheet.Length |
|||
Una volta creato e salvato (e denominato) il documento master con il foglio di calcolo, è possibile creare dei documenti dipendenti. Supponendo che il documento master sia stato denominato "master", il foglio di calcolo sia stato rinominato "modelConstants" e a una cella sia stato assegnato un nome alias "Length", il valore è accessibile come "master#modelConstants.Length". Notare che il documento master deve sempre essere caricato affinché i valori nel master siano disponibili per il documento dipendente. |
|||
</div> |
|||
master#modelConstants.Length |
|||
Unfortunately, the integrated is more confusing than helping because it always gives parser errors or claims that this or that doesn't exist. So, just continue on typing. When you are finished and the content is correct the OK suddenly becomes active. |
|||
Note that the master document must be loaded for the values in the master to be available to the dependent document. |
|||
Of course, it's up to you to load the corresponding documents later when you want to change anything. |
|||
Purtroppo, il checker integrato a volte afferma che un nome valido non esiste. Continuare comunque a digitare. Quando il riferimento è completato, il pulsante {{Button|OK}} diventa attivo. |
|||
Naturalmente, dopo spetta all'utente il compito di caricare i documenti corrispondenti, quando si desidera cambiare qualcosa. |
|||
== Problemi noti / attività rimanenti == |
== Problemi noti / attività rimanenti == |
||
* I grafici delle dipendenze si basano sul rapporto tra gli oggetti del documento, non sulle proprietà. Questo significa che non è possibile fornire i dati a un oggetto e interrogare lo stesso oggetto |
* I grafici delle dipendenze si basano sul rapporto tra gli oggetti del documento, non sulle proprietà. Questo significa che non è possibile fornire i dati a un oggetto e interrogare lo stesso oggetto per i risultati. Ad esempio, anche se non ci sono dipendenze cicliche quando vengono considerate solo le proprietà, non si può avere un oggetto che ottiene le sue dimensioni da un foglio di calcolo e quindi visualizza il volume di tale oggetto nello stesso foglio di calcolo. Per aggirare il problema, utilizzare più fogli di calcolo, ad esempio uno per sviluppare il modello, e uno per i rapporti. |
||
* Il parser delle espressioni non gestisce bene le parentesi e non è in grado di analizzare correttamente alcune espressioni. Ad esempio: "'''= (A1 > A2) ? 1 : 0'''" restituisce un errore, mentre "'''= A1 > A2 ? 1 : 0'''" è accettato. L'espressione "'''= 5 + ((A1>A2) ? 1 : 0)'''" non può essere inserita in nessuna forma. |
|||
* Non è implementato nessun gestore delle espressioni in cui siano elencate tutte le espressioni di un documento, e possano essere create, eliminate, interrogate, ecc |
|||
* Non è implementato nessun gestore delle espressioni in cui siano elencate tutte le espressioni di un documento, e possano essere create, eliminate, interrogate, ecc. |
|||
* I nomi dei vincoli di Sketcher non devono contenere spazi vuoti quando il valore è calcolato da un'espressione, vedere questa [https://forum.freecadweb.org/viewtopic.php?p=302500#p302381; discussione nel forum]. |
|||
* I bug aperti per le espressioni si trovano in [https://freecadweb.org/tracker/set_project.php?project_id=4;20 FreeCAD Bugtracker Expressions category] |
|||
{{Userdocnavi/it}} |
|||
[[Category:User Documentation/it]] |
[[Category:User Documentation/it]] |
||
[[Category:API/it]] |
|||
{{clear}} |
{{clear}} |
||
<languages/> |
Revision as of 21:57, 11 October 2019
Descrizione
È possibile definire le proprietà utilizzando espressioni matematiche. Nella GUI, gli spin box o i campi di input che sono legati alle proprietà contengono un'icona blu File:Sketcher Expressions.png. Cliccando sull'icona, oppure digitando il segno di uguale (=), si porta in primo piano l'editor delle espressioni per quella particolare proprietà.
Una espressione di FreeCAD è un'espressione matematica che segue la notazione per gli operatori matematici standard e le funzioni come descritto in seguito. Inoltre, l'espressione può fare riferimento ad altre proprietà, e anche utilizzare le condizioni. I numeri di un'espressione possono opzionalmente essere collegati ad una unità di misura.
Numbers may use either a comma ',' or a decimal point '.' separating whole digits from decimals. When the decimal marker is used, it must be followed by at least one digit. Thus, the expressions 1.+2. and 1,+2, are invalid, but 1.0 + 2.0 and 1,0 + 2,0 are valid.
Gli operatori e le funzioni sono unit-aware (consapevoli delle unità), e richiedono combinazioni di unità valide, se sono fornite. Ad esempio, 2mm + 4mm è un'espressione valida, mentre 2mm + 4 non lo è (il motivo di questo è che un'espressione come 1in + 4 molto probabilmente viene interpretata come 1in + 4in da un umano, ma tutte le unità vengono convertite nel sistema SI interno, e il sistema non è in grado di indovinare questo). Queste unità sono attualmente riconosciute.
You can use predefined constants and functions.
Referencing objects
You can reference to an object by its Name
or by its Label
. In the case of a Label
, it must be enclosed in double <<
and >>
symbols, such as <<Label>>
.
You can reference any numerical property of this object. For example, to refer to a Cylinder's height, you may use Cylinder.Height
or <<Long_name_of_cylinder>>.Height
.
To reference list objects, the syntax is object_name.list[list_index]
. If you want for example reference a constraint in a sketch, hover with the mouse over this constraint and look in the footer of FreeCAD's main window. Assuming you see there Sketch_name.Constraint17, then you reference it this way: Sketch_name.Constraints[16] (The index starts with 0, therefore constraint 17 has the index 16.) If you are in the same sketch you can omit its name and just use Constraints[16].
For more info about referencing objects, see this section.
Supported Operators
The following operators are supported:
Operator | Description |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
^ | Exponentiation |
Costanti supportate
Description: Ceiling
Returns: The smallest integer value greater than or equal to x introduced in version 0.16
Description: Floor
Returns: The largest integer value less than or equal to x introduced in version 0.16
Description:
Returns: x rounded to the nearest integer introduced in version 0.16
Description: Truncate
Returns: x truncated to the nearest integer introduced in version 0.16
Funzioni Supportate
Funzioni matematiche generali
Le funzioni matematiche elencate di seguito sono disponibili.
Multiple arguments to a function may be separated by either a semicolon ';' or a comma followed by a space ', '. In the latter case, the comma is converted to a semicolon after entry. When a semicolon is used, no trailing space is necessary.
Trigonometric functions use degree as their default unit. For radian measure, add rad following the first value in an expression. So e.g. cos(45) is the same as cos(pi rad / 4).
These trigonometric functions are supported:
Function | Description | Value range |
---|---|---|
acos(x) | Arc cosine | -1 <= x <= 1 |
asin(x) | Arc sine | -1 <= x <= 1 |
atan(x) | Arc tangent | all |
atan2(x, y) | Arc tangent of x/y | all, except y = 0 |
cos(x) | Cosine | all |
cosh(x) | Hyperbolic cosine | all |
sin(x) | Sine | all |
sinh(x) | Hyperbolic sine | all |
tan(x) | Tangent | all, except of x = n·90 with n = integer |
tanh(x) | Hyperbolic tangent | all |
These functions for exponentiation and logarithmization are supported:
Function | Description | Value range |
---|---|---|
exp(x) | Exponential function | all |
log(x) | Natural logarithm | x > 0 |
log10(x) | Common logarithm | x > 0 |
pow(x, y) | Exponentiation | all |
sqrt(x) | Square root | x >= 0 |
These functions for rounding, truncation and remainder are supported:
Function | Description | Value range |
---|---|---|
abs(x) | Absolute value | all |
ceil(x) | Ceiling function smallest integer value greater than or equal to x | all |
floor(x) | Floor function, largest integer value less than or equal to x | all |
mod(x, y) | Remainder after dividing x by y | all, except y = 0 |
round(x) | Rounding to the nearest integer | all |
trunc(x) | Truncation to the nearest integer | all |
Statistica / Funzioni di aggregazione
Le funzioni di aggregazione elencate di seguito sono supportate. Le funzioni di aggregazione accettano uno o più argomenti, separati da un punto e virgola ';' o una virgola e uno spazio ", ". Gli argomenti possono includere riferimenti a celle di un foglio di calcolo; i riferimenti alla cella sono costituiti dalla lettera di riga (Maiuscola) seguita dal numero di colonna. Gli argomenti possono includere intervalli di celle (due riferimenti di cella separati da due punti). Esempio: average(B1:B8)
Description: Number of cells from x through y
Returns: The number of cells from x through y, inclusive
Description: Standard deviation of values in cells x through y
Returns: Standard deviation
Espressioni condizionali
Le espressioni condizionali sono nella forma condition ? resultTrue : resultFalse
The following relational operators are defined:
Unit | Description |
---|---|
== | equal to |
!= | not equal to |
> | greater than |
< | less than |
>= | greater than or equal to |
<= | less than or equal to |
Unità
Units can directly be used in expressions. The parser connects them to the previous value. So '2mm' or '2 mm' is valid while ' mm' is invalid because there is no preceding value.
All values must have a unit. Therefore you must in general use a unit for values in spreadsheets.
In some cases it works even without a unit, for example if you have e.g. in spreadsheet cell B1 just the number 1.5 and refer to it for a pad height. This only works because the pad height predefines the unit mm that is used if no unit is given. It will nevertheless fail if you use for the pad height e.g. Sketch1.Constraints.Width - Spreadsheet.B1 because Sketch1.Constraints.Width has a unit and Spreadsheet.B1 has not.
Units with exponents can directly be entered. So e.g. mm^3 will be recognized as mm³ and m^3 will be recognized as m³.
Le funzioni trigonometriche usano i gradi come unità predefinita. Per le misurazioni che utilizzano il radiante, aggiungere rad dopo il primo valore angolare nell'espressione. Esempio: cos(45) è equivalente a cos(pi rad/4).
The following units are recognized by the expression parser:
Amount of substance:
Unit | Description |
---|---|
mol | Mole |
Angle:
Unit | Description |
---|---|
° | Degree; alternative to the unit deg |
deg | Degree; alternative to the unit ° |
rad | Radian |
gon | Gradian |
S | Second of arc |
″ | Second of arc; alternative to the unit S |
M | Minute of arc |
′ | Minute of arc; alternative to the unit M |
Current:
Unit | Description |
---|---|
mA | Milliampere |
A | Ampere |
kA | Kiloampere |
MA | Megaampere |
Energy / Work:
Unit | Description |
---|---|
J | Joule |
Ws | Watt second; alternative to the unit Joule |
VAs | Volt-ampere-second; alternative to the unit Joule |
CV | Coulomb·Volt; alternative to the unit Joule |
Force:
Unit | Description |
---|---|
mN | Millinewton |
N | Newton |
kN | Kilonewton |
MN | Meganewton |
lbf | Pound of force |
Length:
Unit | Description |
---|---|
nm | Nanometer |
um | Micrometer; alternative to the unit µm |
µm | Micrometer; alternative to the unit mu |
mm | Millimeter |
cm | Centimeter |
mm | Millimeter |
dm | Decimeter |
m | Meter |
km | Kilometer |
mil | Thousandth of an inch; alternative to the unit thou |
thou | Thousandth of an inch; alternative to the unit mil |
in | Inch |
ft | Foot; alternative to the unit ' |
' | Foot; alternative to the unit ft |
yd | Yard |
mi | Mile |
Luminous intensity:
Unit | Description |
---|---|
cd | Candela |
Mass:
Unit | Description |
---|---|
ug | Microgram; alternative to the unit µg |
µg | Microgram; alternative to the unit ug |
mg | Milligram |
g | Gram |
kg | Kilogram |
t | Tonne |
oz | Ounce |
lb | Pound; alternative to the unit lbm |
lbm | Pound; alternative to the unit lb |
st | Stone |
cwt | Hundredweight |
Power:
Unità | Descrizione |
---|---|
W | Watt |
VA | Volt-ampere |
Pressure:
Unit | Description |
---|---|
Pa | Pascal |
kPa | Kilopascal |
MPa | Megapascal |
GPa | Gigapascal |
uTorr | Microtorr; alternative to the unit µTorr |
µTorr | Microtorr; alternative to the unit uTorr |
mTorr | Millitorr |
Torr | Torr |
psi | Pound-force per square inch |
ksi | Kilopound-force per square inch |
Temperature:
Unit | Description |
---|---|
uK | Microkelvin; alternative to the unit µK |
µK | Microkelvin; alternative to the unit uK |
mK | Millikelvin |
K | Kelvin |
Time:
Unit | Description |
---|---|
s | Second |
min | Minute |
h | Hour |
Torque:
Unit | Description |
---|---|
Nm | Newton metre |
Volume:
Unit | Description |
---|---|
l | Liter |
The following commonly used units are not yet supported:
Unit | Description | Alternative |
---|---|---|
C | Coulomb | 1 A*s |
Hz | Hertz | 1 /s |
V | Volt | 1 W/A |
eV | Electronvolt | 1.602176634e-19 J |
kWh | Kilowatt hour | 3.6e6 J |
bar | Bar | 100 kPa |
T | Tesla | 1 kg/s^2/A |
F | Farad | 1 s^4*A^2/m^2/kg |
H | Henry | 1 kg*m^2/s^2/A^2 |
u | Atomic mass unit; alternative to the unit 'Da' | 1.66053906660e-27 kg |
Da | Dalton; alternative to the unit 'u' | 1.66053906660e-27 kg |
cal | Calorie | 4.184 J |
sr | Steradian | not directly |
lm | Lumen | not directly |
lx | Lux | not directly |
Mpsi | Megapound-force per square inch | 1000 ksi |
Riferimento ai dati CAD
In un'espressione è possibile utilizzare i dati del modello stesso. Per fare riferimento a una proprietà usare object.property. Se la proprietà è un composto di campi, è possibile accedere ai singoli campi come object.property.field.
La tabella seguente mostra alcuni esempi:
Dati CAD | Chiamata nell'espressione | Risultato |
---|---|---|
Lunghezza parametrica di un Cubo di Parte | Cube.Length | Lunghezza con unità in mm |
Volume del Cubo | Cube.Shape.Volume | Volume in mm³ senza unità |
Tipo di forma del Cubo | Cube.Shape.ShapeType | Stringa: Solid |
Etichetta del Cubo | Cube.Label | Stringa: Label |
coordinata x del centro di massa del Cubo | Cube.Shape.CenterOfMass.x | coordinata x in mm senza unità |
Valore di un vincolo in uno schizzo | Constraints.Width | Valore numerico del vincolo di nome 'Width' nello schizzo, se l'espressione è utilizzata nello schizzo stesso. |
Valore di un vincolo in uno schizzo | MySketch.Constraints.Width | Valore numerico del vincolo di nome 'Width' nello schizzo, se l'espressione è usata al di fuori dello schizzo. |
Valore di un alias in spreadsheet | Spreadsheet.Depth | Valore dell'alias "Depth" nel foglio "Spreadsheet" |
Valore di una proprietà locale | Length | Valore della proprietà Length, ad es. di un oggetto Pad, oppure Length2 nello stesso oggetto se l'espressione è già usata. |
Variabili globali nell'ambito del documento
Al momento in FreeCAD non esiste il concetto di variabili globali. Invece, utilizzando l'ambiente Spreadsheet, si possono definire delle variabili arbitrarie come celle in un foglio di calcolo, e poi assegnare loro un nome utilizzando la proprietà alias della cella (tasto destro del mouse sulla cella). Dopo si può accedere alla variabile da qualsiasi espressione, come per qualsiasi altra proprietà di un oggetto.
Riferimenti incrociati nel documento
In un documento è possibile fare riferimento a un foglio di calcolo contenuto in un altro documento.
È possibile utilizzare il nome di un documento per fare riferimento ad esso da altri documenti. Quando si salva un documento per la prima volta, si sceglie un nome per il file; questo di solito è diverso dal default iniziale "Unnamed1" (o il suo equivalente tradotto). Per evitare la perdita dei collegamenti quando il documento master viene rinominato al momento del salvataggio, si consiglia di creare prima il documento master, creare un foglio di calcolo al suo interno e salvarlo. Successivamente è ancora possibile apportare modifiche e salvare il file, ma non si deve rinominarlo.
Una volta creato e salvato (e denominato) il documento master con il foglio di calcolo, è possibile creare dei documenti dipendenti. Supponendo che il documento master sia stato denominato "master", il foglio di calcolo sia stato rinominato "modelConstants" e a una cella sia stato assegnato un nome alias "Length", il valore è accessibile come "master#modelConstants.Length". Notare che il documento master deve sempre essere caricato affinché i valori nel master siano disponibili per il documento dipendente.
master#modelConstants.Length
Note that the master document must be loaded for the values in the master to be available to the dependent document.
Purtroppo, il checker integrato a volte afferma che un nome valido non esiste. Continuare comunque a digitare. Quando il riferimento è completato, il pulsante OK diventa attivo.
Naturalmente, dopo spetta all'utente il compito di caricare i documenti corrispondenti, quando si desidera cambiare qualcosa.
Problemi noti / attività rimanenti
- I grafici delle dipendenze si basano sul rapporto tra gli oggetti del documento, non sulle proprietà. Questo significa che non è possibile fornire i dati a un oggetto e interrogare lo stesso oggetto per i risultati. Ad esempio, anche se non ci sono dipendenze cicliche quando vengono considerate solo le proprietà, non si può avere un oggetto che ottiene le sue dimensioni da un foglio di calcolo e quindi visualizza il volume di tale oggetto nello stesso foglio di calcolo. Per aggirare il problema, utilizzare più fogli di calcolo, ad esempio uno per sviluppare il modello, e uno per i rapporti.
- Il parser delle espressioni non gestisce bene le parentesi e non è in grado di analizzare correttamente alcune espressioni. Ad esempio: "= (A1 > A2) ? 1 : 0" restituisce un errore, mentre "= A1 > A2 ? 1 : 0" è accettato. L'espressione "= 5 + ((A1>A2) ? 1 : 0)" non può essere inserita in nessuna forma.
- Non è implementato nessun gestore delle espressioni in cui siano elencate tutte le espressioni di un documento, e possano essere create, eliminate, interrogate, ecc.
- I nomi dei vincoli di Sketcher non devono contenere spazi vuoti quando il valore è calcolato da un'espressione, vedere questa discussione nel forum.
- I bug aperti per le espressioni si trovano in FreeCAD Bugtracker Expressions category
- Getting started
- Installation: Download, Windows, Linux, Mac, Additional components, Docker, AppImage, Ubuntu Snap
- Basics: About FreeCAD, Interface, Mouse navigation, Selection methods, Object name, Preferences, Workbenches, Document structure, Properties, Help FreeCAD, Donate
- Help: Tutorials, Video tutorials
- Workbenches: Std Base, Arch, Assembly, CAM, Draft, FEM, Inspection, Mesh, OpenSCAD, Part, PartDesign, Points, Reverse Engineering, Robot, Sketcher, Spreadsheet, Start, Surface, TechDraw, Test Framework, Web
- Hubs: User hub, Power users hub, Developer hub