Expressions/it: Difference between revisions

From FreeCAD Documentation
(Created page with "== Riferimento ai dati CAD ==")
(Created page with "In un'espressione è possibile utilizzare i dati provenienti da altre parti della costruzione. La sintassi per un riferimento a un campo è il seguente: object.property. Se la...")
Line 23: Line 23:
== Riferimento ai dati CAD ==
== Riferimento ai dati CAD ==


It is possible to use data from other parts of the construction in an expression. The syntax for a reference to a field is as follows: object.property. If the property is a compound of fields, they can be accessed by e.g object.property.field.
In un'espressione è possibile utilizzare i dati provenienti da altre parti della costruzione. La sintassi per un riferimento a un campo è il seguente: object.property. Se la proprietà è un composto di campi, si può accedere ad esempio con object.property.field.


The following table shows some examples:
The following table shows some examples:

Revision as of 19:20, 8 October 2015

introduced in version 0.16

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 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 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.

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 SI sistema interno, e il sistema non è in grado di indovinare questo).

Funzioni Supportate

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 trigonometriche utilizzano i gradi come unità di default; fornire "rad" se si desidera che utilizzino i radianti.

Le costanti pi greco ed e sono predefinite

L'istruzione condizionale funziona così: = condition ? resultTrue : resultFalse

La condizione è definita come un'espressione che restituisce 0 (per false) o non-zero per true. Sono definiti i seguenti operatori di confronto: ==, !=, >, <, >=, and <=.

Le formule sono scritte in questo modo: 2 * Length, dove Length è una proprietà contenuta nell'oggetto dell'espressione.

Riferimento ai dati CAD

In un'espressione è possibile utilizzare i dati provenienti da altre parti della costruzione. La sintassi per un riferimento a un campo è il seguente: object.property. Se la proprietà è un composto di campi, si può accedere ad esempio con object.property.field.

The following table shows some examples:

CAD-Data Call in expression Result
Parametric Length of a Part-Workbench Cube Cube.Length Length with units mm
Volume of the Cube Cube.Shape.Volume Volume in mm³ without units
Type of the Cube-shape Cube.Shape.ShapeType String: Solid
Label of the Cube Cube.Label String: Cube
x-coordinate of center of mass of the Cube Cube.Shape.CenterOfMass.x x-coordinate in mm without units
Value of constraint in a sketch Constraints.Width Numeric value of the named constraint 'Width' in the sketch

Global variables

There is no concept of global variables in FreeCAD at the moment. Instead, arbitrary variables can be defined as cells in a spreadsheet using the Spreadsheet workbench, and then be given a name using the alias property for the cell (right-click on cell). Then they can be accessed from any expression just as any other object property.

Known issues / remaining tasks

  • The dependency graphs is based on the relationship between document objects, not properties. This means that you cannot provide data to and query the same object in e.g a spreadsheet, even though there are no cyclic dependency when just the properties are considered. As a work-around, use multiple spreadsheets, e.g one to drive your model, and one for reporting.
  • There is no expression manager implemented where all expressions in a document are listed, and can be created, deleted, queries, etc.
  • The Data properties tab does not yet support expressions.
  • Renaming aliases or inserting/removing rows/columns in a spreadsheet will not propagate changes to expressions in the document.