Difference between revisions of "Expressions"
(add info how to reference lists and refactor page a bit) 
(remove newton metre because it is just a compound unit not a unit on its own) 

(115 intermediate revisions by 11 users not shown)  
Line 1:  Line 1:  
<languages/>  <languages/>  
−  +  {{TOCright}}  
−  
<translate>  <translate>  
Line 7:  Line 6:  
<!T:2>  <!T:2>  
−  It is possible to define properties using mathematical expressions.  +  It is possible to define properties using mathematical expressions. In the GUI, spin boxes or input fields that are bound to properties contain a blue icon [[Image:Sketcher_Expressions.png24px]]. Clicking on the icon or typing the equal sign {{KEY=}} brings up the expression editor for that particular property. 
<!T:3>  <!T:3>  
Line 13:  Line 12:  
<!T:54>  <!T:54>  
−  Numbers may use either a comma  +  Numbers may use either a comma {{incode,}} or a decimal point {{incode.}} separating whole digits from decimals. 
When the decimal marker is used, it ''must'' be followed by at least one digit.  When the decimal marker is used, it ''must'' be followed by at least one digit.  
−  Thus, the expressions  +  Thus, the expressions {{incode1.+2.}} and {{incode1,+2,}} are invalid, but {{incode1.0 + 2.0}} and {{incode1,0 + 2,0}} are valid. 
<!T:4>  <!T:4>  
−  Operators and functions are unitaware, and require valid combinations of units, if supplied. For example,  +  Operators and functions are unitaware, and require valid combinations of units, if supplied. For example, {{incode2mm + 4mm}} is a valid expression, while {{incode2mm + 4}} is not (the reason for this is that an expression like {{incode1in + 4}} will most likely be interpreted as {{incode1in + 4in}} by humans, but all units are converted to the SI system internally, and the system is not able to guess this). These [[#Unitsunits]] are currently recognized. 
<!T:27>  <!T:27>  
−  You can use [[#  +  You can use [[#Supported_constantspredefined constants]] and [[#Supported_functionsfunctions]]. 
+  
+  ===Function Arguments=== <!T:97>  
+  
+  <!T:28>  
+  Multiple arguments to a function may be separated by either a semicolon {{incode;}} or a comma <em>followed by a space</em> {{incode, }}. In the latter case, the comma is converted to a semicolon after entry. When a semicolon is used, no trailing space is necessary.  
−  ===Referencing objects===  +  <!T:98> 
+  Arguments may include references to cells in a spreadsheet. A cell reference consists of the cell's uppercase row letter followed by its column number, for example {{IncodeA1}}. A cell may also be referenced by using the cell's alias instead, for example {{incodeSpreadsheet.MyPartWidth}}.  
+  
+  ===Referencing objects=== <!T:69>  
<!T:67>  <!T:67>  
−  You can reference  +  You can reference an object by its {{PropertyDataName}} or by its {{PropertyDataLabel}}. In the case of a {{PropertyDataLabel}}, it must be enclosed in double {{incode<<}} and {{incode>>}} symbols, such as {{incode<<Label>>}}. 
−  You can reference any numerical property of  +  <!T:70> 
+  You can reference any numerical property of an object. For example, to reference a Cylinder's height, you may use {{incodeCylinder.Height}} or {{incode<<Long_name_of_cylinder>>.Height}}.  
−  To reference list objects,  +  <!T:71> 
+  To reference list objects, use {{incode<<object_label>>.list[list_index]}} or {{incodeobject_name.list[list_index]}}. If you want for example to reference a constraint in a sketch, use {{incode<<MySketch>>.Constraints[16]}}. If you are in the same sketch you may omit its name and just use {{incodeConstraints[16]}}.<br/>  
+  '''Note:''' The index starts with 0, therefore constraint 17 has the index 16.  
−  ==Supported  +  <!T:72> 
+  For more information about referencing objects, see [[#Reference_to_CAD_dataReference to CAD_data]].  
+  
+  == Supported constants == <!T:58>  
+  
+  <!T:59>  
+  The following constants are supported:  
+  { class="wikitable floatright mwcollapsible mwuncollapsed"  
+  !style="width: 33%;"Constant  
+  !style="width: 66%;"Description  
+    
+   style="textalign:center;"  '''e'''  
+   [https://en.wikipedia.org/wiki/E_(mathematical_constant) Euler's number]  
+    
+   style="textalign:center;"  '''pi'''  
+   [https://en.wikipedia.org/wiki/Pi Pi]  
+  }  
+  
+  == Supported operators == <!T:96>  
<!T:53>  <!T:53>  
Line 40:  Line 68:  
!style="width: 66%;"Description  !style="width: 66%;"Description  
    
−   +  +   style="textalign:center;" '''+''' 
 [https://en.wikipedia.org/wiki/Addition Addition]   [https://en.wikipedia.org/wiki/Addition Addition]  
    
−     +   style="textalign:center;" '''''' 
 [https://en.wikipedia.org/wiki/Subtraction Subtraction]   [https://en.wikipedia.org/wiki/Subtraction Subtraction]  
    
−   *  +   style="textalign:center;"  '''*''' 
 [https://en.wikipedia.org/wiki/Multiplication Multiplication]   [https://en.wikipedia.org/wiki/Multiplication Multiplication]  
    
−   /  +   style="textalign:center;"  '''/''' 
−   [https://en.wikipedia.org/wiki/Division_(mathematics) Division]  +   Floating point [https://en.wikipedia.org/wiki/Division_(mathematics) Division] 
+    
+   style="textalign:center;"  '''%'''  
+   [https://en.wikipedia.org/wiki/Remainder Remainder]  
    
−   ^  +   style="textalign:center;"  '''^''' 
 [https://en.wikipedia.org/wiki/Exponentiation Exponentiation]   [https://en.wikipedia.org/wiki/Exponentiation Exponentiation]  
}  }  
−  ==Supported  +  == Supported functions == <!T:5> 
−  +  === General mathematical functions === <!T:55>  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  === General  
<!T:7>  <!T:7>  
The mathematical functions listed below are available.  The mathematical functions listed below are available.  
−  
−  
−  
<!T:29>  <!T:29>  
−  [https://en.wikipedia.org/wiki/Trigonometric_functions Trigonometric functions] use degree as their default unit. For radian measure, add  +  [https://en.wikipedia.org/wiki/Trigonometric_functions Trigonometric functions] use degree as their default unit. For radian measure, add {{incoderad}} following the <em>first</em> value in an expression. So e.g. {{incodecos(45)}} is the same as {{incodecos(pi rad / 4)}}. Expressions in degrees can use either {{incodedeg}} or {{incode°}}, e.g. {{incode360deg  atan2(3; 4)}} or {{incode360°  atan2(3; 4)}}. If an expression is without units and needs to be converted to degrees or radians for compatibility, multiply by {{incode1 deg}}, {{incode1 °}} or {{incode1 rad}} as appropriate, e.g. {{incode(360  X) * 1deg}}; {{incode(360  X) * 1°}}; {{incode(0.5 + pi / 2) * 1rad}}. <br/> 
These trigonometric functions are supported:  These trigonometric functions are supported:  
{ class="wikitable floatright mwcollapsible mwcollapsed"  { class="wikitable floatright mwcollapsible mwcollapsed"  
Line 170:  Line 183:  
    
 ceil(x)   ceil(x)  
−   [https://en.wikipedia.org/wiki/Floor_and_ceiling_functions Ceiling function] smallest integer value greater than or equal to x  +   [https://en.wikipedia.org/wiki/Floor_and_ceiling_functions Ceiling function], smallest integer value greater than or equal to x 
 all   all  
    
Line 186:  Line 199:  
    
 trunc(x)   trunc(x)  
−   [https://en.wikipedia.org/wiki/Truncation Truncation] to the nearest integer  +   [https://en.wikipedia.org/wiki/Truncation Truncation] to the nearest integer in the direction of zero 
 all   all  
}  }  
−  === Statistical /  +  === Statistical / aggregate functions === <!T:99> 
−  [https://en.wikipedia.org/wiki/Aggregate_function Aggregate functions] take one or more arguments  +  
−  +  <!T:8>  
−  +  [https://en.wikipedia.org/wiki/Aggregate_function Aggregate functions] take one or more arguments.<br>  
+  
+  <!T:100>  
+  Individual arguments to aggregate functions may consist of ranges of cells. A range of cells is expressed as two cell references separated by a colon {{Incode:}}, for example {{Incodeaverage(B1:B8)}} or {{Incodesum(A1:A4; B1:B4)}}.  
+  The cell references may also use cell aliases, for example {{Incodeaverage(StartTemp:EndTemp)}} {{Version0.19}}.  
<!T:60>  <!T:60>  
Line 202:  Line 219:  
!style="width: 25%;"Value range  !style="width: 25%;"Value range  
    
−   average(  +   average(a; b; c; ...) 
−   [https://en.wikipedia.org/wiki/Arithmetic_mean  +   [https://en.wikipedia.org/wiki/Arithmetic_mean Average] value of the arguments; same as sum(a; b; c; ...) / count(a; b; c; ...) 
 all   all  
    
−   count(  +   count(a; b; c; ...) 
−   [https://en.wikipedia.org/wiki/Counting  +   [https://en.wikipedia.org/wiki/Counting Count] of the arguments; typically used for cell ranges 
 all   all  
    
−   max(  +   max(a; b; c; ...) 
−   [https://en.wikipedia.org/wiki/Maxima_and_minima Maximum] value  +   [https://en.wikipedia.org/wiki/Maxima_and_minima Maximum] value of the arguments 
 all   all  
    
−   min(  +   min(a; b; c; ...) 
−   [https://en.wikipedia.org/wiki/Maxima_and_minima Minimum] value  +   [https://en.wikipedia.org/wiki/Maxima_and_minima Minimum] value of the arguments 
 all   all  
    
−   stddev(  +   stddev(a; b; c; ...) 
−   [https://en.wikipedia.org/wiki/  +   [https://en.wikipedia.org/wiki/standard_deviation Standard deviation] of the values of the arguments 
 all   all  
    
−   sum(  +   sum(a; b; c; ...) 
−   [https://en.wikipedia.org/wiki/Summation Sum] of values  +   [https://en.wikipedia.org/wiki/Summation Sum] of the values of the arguments; typically used for cell ranges 
 all   all  
}  }  
−  == Conditional  +  == Conditional expressions == <!T:32> 
<!T:10>  <!T:10>  
−  Conditional expressions are of the form  +  Conditional expressions are of the form {{incodecondition ? resultTrue : resultFalse}}. The condition is defined as an expression that evaluates to either {{incode0}} (false) or nonzero (true). 
+  Note that enclosing the conditional expression in parentheses is currently considered an error. {{VersionMinus0.19}}  
<!T:33>  <!T:33>  
Line 238:  Line 256:  
!style="width: 66%;"Description  !style="width: 66%;"Description  
    
−   ==  +   style="textalign:center;"  '''==''' 
 equal to   equal to  
    
−   !=  +   style="textalign:center;"  '''!=''' 
 not equal to   not equal to  
    
−   >  +   style="textalign:center;"  '''>''' 
 greater than   greater than  
    
−   <  +   style="textalign:center;"  '''<''' 
 less than   less than  
    
−   >=  +   style="textalign:center;"  '''>=''' 
 greater than or equal to   greater than or equal to  
    
−   <=  +   style="textalign:center;"  '''<=''' 
 less than or equal to   less than or equal to  
}  }  
Line 260:  Line 278:  
<!T:35>  <!T:35>  
−  Units can  +  Units can be used directly in expressions. The parser connects them to the previous value. So {{incode2mm}} or {{incode2 mm}} is valid while {{incodemm}} is invalid because there is no preceding value. 
<!T:56>  <!T:56>  
All values must have a unit. Therefore you must in general use a unit for values in spreadsheets.<br/>  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  +  In some cases it works even without a unit, for example if you have e.g. in spreadsheet cell B1 just the number {{incode1.5}} and refer to it for a pad height. This only works because the pad height predefines the unit {{incodemm}} that is used if no unit is given. It will nevertheless fail if you use for the pad height e.g. {{incodeSketch1.Constraints.Width  Spreadsheet.B1}} because {{incodeSketch1.Constraints.Width}} has a unit and {{incodeSpreadsheet.B1}} has not. 
<!T:57>  <!T:57>  
−  Units with exponents can directly be entered. So e.g.  +  Units with exponents can directly be entered. So e.g. {{incodemm^3}} will be recognized as mm³ and {{incodem^3}} will be recognized as m³. 
<!T:36>  <!T:36>  
−  If you have a variable  +  If you have a variable whose name is that of a unit you must put the variable between {{incode<< >>}} to prevent it from being recognized as a unit. For example if you have the dimension {{incodeSketch.Constraints.A}} it would be recognized as the unit ampere. Therefore you must write it in the expression as {{incodeSketch.Constraints.<<A>>}}. 
<!T:37>  <!T:37>  
Line 280:  Line 298:  
!style="width: 33%;"Unit  !style="width: 33%;"Unit  
!style="width: 66%;"Description  !style="width: 66%;"Description  
+    
+   mmol  
+   Milli[https://en.wikipedia.org/wiki/Mole_(unit) mole]  
    
 mol   mol  
Line 333:  Line 354:  
 MA   MA  
 Mega[https://en.wikipedia.org/wiki/Ampere ampere]   Mega[https://en.wikipedia.org/wiki/Ampere ampere]  
+  }  
+  
+  <!T:75>  
+  Electrical capacitance:  
+  { class="wikitable floatright mwcollapsible mwcollapsed"  
+  !style="width: 33%;"Unit  
+  !style="width: 66%;"Description  
+    
+   pF  
+   Pico[https://en.wikipedia.org/wiki/Farad farad], {{Version0.19}}  
+    
+   nF  
+   Nano[https://en.wikipedia.org/wiki/Farad farad], {{Version0.19}}  
+    
+   uF  
+   Micro[https://en.wikipedia.org/wiki/Farad farad]; alternative to the unit ''µF'', {{Version0.19}}  
+    
+   µF  
+   Micro[https://en.wikipedia.org/wiki/Farad farad]; alternative to the unit ''uF'', {{Version0.19}}  
+    
+   mF  
+   Milli[https://en.wikipedia.org/wiki/Farad farad], {{Version0.19}}  
+    
+   F  
+   [https://en.wikipedia.org/wiki/Farad Farad]; 1 F = 1 s^4·A^2/m^2/kg, {{Version0.19}}  
+  }  
+  
+  <!T:79>  
+  Electrical conductance:  
+  { class="wikitable floatright mwcollapsible mwcollapsed"  
+  !style="width: 33%;"Unit  
+  !style="width: 66%;"Description  
+    
+   uS  
+   Micro[https://en.wikipedia.org/wiki/Siemens_(unit) siemens]; alternative to the unit ''µS'', {{Version0.19}}  
+    
+   µS  
+   Micro[https://en.wikipedia.org/wiki/Siemens_(unit) siemens]; alternative to the unit ''uS'', {{Version0.19}}  
+    
+   mS  
+   Milli[https://en.wikipedia.org/wiki/Siemens_(unit) siemens], {{Version0.19}}  
+    
+   S  
+   [https://en.wikipedia.org/wiki/Siemens_(unit) Siemens]; 1 S = 1 s^3·A^2/kg/m^2, {{Version0.19}}  
+    
+   kS  
+   Kilo[https://en.wikipedia.org/wiki/Siemens_(unit) siemens], {{Version0.20}}  
+    
+   MS  
+   Mega[https://en.wikipedia.org/wiki/Siemens_(unit) siemens], {{Version0.20}}  
+  }  
+  
+  <!T:76>  
+  Electrical inductance:  
+  { class="wikitable floatright mwcollapsible mwcollapsed"  
+  !style="width: 33%;"Unit  
+  !style="width: 66%;"Description  
+    
+   nH  
+   Nano[https://en.wikipedia.org/wiki/Henry_(unit) henry], {{Version0.19}}  
+    
+   uH  
+   Micro[https://en.wikipedia.org/wiki/Henry_(unit) henry]; alternative to the unit ''µH'', {{Version0.19}}  
+    
+   µH  
+   Micro[https://en.wikipedia.org/wiki/Henry_(unit) henry]; alternative to the unit ''uH'', {{Version0.19}}  
+    
+   mH  
+   Milli[https://en.wikipedia.org/wiki/Henry_(unit) henry], {{Version0.19}}  
+    
+   H  
+   [https://en.wikipedia.org/wiki/Henry_(unit) Henry]; 1 H = 1 kg·m^2/s^2/A^2, {{Version0.19}}  
+  }  
+  
+  <!T:80>  
+  Electrical resistance:  
+  { class="wikitable floatright mwcollapsible mwcollapsed"  
+  !style="width: 33%;"Unit  
+  !style="width: 66%;"Description  
+    
+   Ohm  
+   [https://en.wikipedia.org/wiki/Ohm Ohm]; 1 Ohm = 1 kg·m^2/s^3/A^2, {{Version0.19}}  
+    
+   kOhm  
+   Kilo[https://en.wikipedia.org/wiki/Ohm ohm], {{Version0.19}}  
+    
+   MOhm  
+   Mega[https://en.wikipedia.org/wiki/Ohm ohm], {{Version0.19}}  
+  }  
+  
+  <!T:73>  
+  Electric charge:  
+  { class="wikitable floatright mwcollapsible mwcollapsed"  
+  !style="width: 33%;"Unit  
+  !style="width: 66%;"Description  
+    
+   C  
+   [https://en.wikipedia.org/wiki/Coulomb Coulomb]; 1 C = 1 A·s, {{Version0.19}}  
+  }  
+  
+  <!T:74>  
+  Electric potential:  
+  { class="wikitable floatright mwcollapsible mwcollapsed"  
+  !style="width: 33%;"Unit  
+  !style="width: 66%;"Description  
+    
+   mV  
+   Milli[https://en.wikipedia.org/wiki/Volt volt]  
+    
+   V  
+   [https://en.wikipedia.org/wiki/Volt Volt]  
+    
+   kV  
+   Kilo[https://en.wikipedia.org/wiki/Volt volt]  
}  }  
<!T:41>  <!T:41>  
−  Energy /  +  Energy / work: 
{ class="wikitable floatright mwcollapsible mwcollapsed"  { class="wikitable floatright mwcollapsible mwcollapsed"  
!style="width: 33%;"Unit  !style="width: 33%;"Unit  
!style="width: 66%;"Description  !style="width: 66%;"Description  
+    
+   mJ  
+   Milli[https://en.wikipedia.org/wiki/Joule joule]  
    
 J   J  
 [https://en.wikipedia.org/wiki/Joule Joule]   [https://en.wikipedia.org/wiki/Joule Joule]  
+    
+   kJ  
+   Kilo[https://en.wikipedia.org/wiki/Joule joule], {{Version0.19}}  
+    
+   eV  
+   [https://en.wikipedia.org/wiki/Electronvolt Electronvolt]; 1 ev = 1.602176634e19 J, {{Version0.19}}  
+    
+   keV  
+   Kilo[https://en.wikipedia.org/wiki/Electronvolt electronvolt], {{Version0.19}}  
+    
+   MeV  
+   Mega[https://en.wikipedia.org/wiki/Electronvolt electronvolt], {{Version0.19}}  
+    
+   kWh  
+   [https://en.wikipedia.org/wiki/Kilowatt_hour Kilowatt hour]; 1 kWh = 3.6e6 J, {{Version0.19}}  
    
 Ws   Ws  
Line 351:  Line 504:  
    
 CV   CV  
−   [https://en.wikipedia.org/wiki/Joule  +   [https://en.wikipedia.org/wiki/Joule Coulombvolt]; alternative to the unit ''Joule'' 
+    
+   cal  
+   [https://en.wikipedia.org/wiki/Calorie Calorie]; 1 cal = 4.184 J, {{Version0.19}}  
+    
+   kcal  
+   Kilo[https://en.wikipedia.org/wiki/Calorie calorie], {{Version0.19}}  
}  }  
Line 385:  Line 544:  
 Nano[https://en.wikipedia.org/wiki/Metre meter]   Nano[https://en.wikipedia.org/wiki/Metre meter]  
    
−    +   mu 
 Micro[https://en.wikipedia.org/wiki/Metre meter]; alternative to the unit ''µm''   Micro[https://en.wikipedia.org/wiki/Metre meter]; alternative to the unit ''µm''  
    
Line 396:  Line 555:  
 cm   cm  
 Centi[https://en.wikipedia.org/wiki/Metre meter]   Centi[https://en.wikipedia.org/wiki/Metre meter]  
−  
−  
−  
    
 dm   dm  
Line 439:  Line 595:  
 cd   cd  
 [https://en.wikipedia.org/wiki/Candela Candela]   [https://en.wikipedia.org/wiki/Candela Candela]  
+  }  
+  
+  <!T:81>  
+  Magnetic field strength:  
+  { class="wikitable floatright mwcollapsible mwcollapsed"  
+  !style="width: 33%;"Unit  
+  !style="width: 66%;"Description  
+    
+   Oe  
+   [https://en.wikipedia.org/wiki/Oersted Oersted]; 1 Oe = 79.57747 A/m, {{Version0.19}}  
+  }  
+  
+  <!T:82>  
+  Magnetic flux:  
+  { class="wikitable floatright mwcollapsible mwcollapsed"  
+  !style="width: 33%;"Unit  
+  !style="width: 66%;"Description  
+    
+   Wb  
+   [https://en.wikipedia.org/wiki/Weber_(unit) Weber]; 1 Wb = 1 kg*m^2/s^2/A, {{Version0.19}}  
+  }  
+  
+  <!T:77>  
+  Magnetic flux density:  
+  { class="wikitable floatright mwcollapsible mwcollapsed"  
+  !style="width: 33%;"Unit  
+  !style="width: 66%;"Description  
+    
+   G  
+   [https://en.wikipedia.org/wiki/Gauss_(unit) Gauss]; 1 G = 1 e4 T, {{Version0.19}}  
+    
+   T  
+   [https://en.wikipedia.org/wiki/Tesla_(unit) Tesla]; 1 T = 1 kg/s^2/A, {{Version0.19}}  
}  }  
Line 489:  Line 678:  
 W   W  
 [https://en.wikipedia.org/wiki/Watt Watt]   [https://en.wikipedia.org/wiki/Watt Watt]  
+    
+   kW  
+   Kilo[https://en.wikipedia.org/wiki/Watt watt], {{Version0.19}}  
    
 VA   VA  
Line 511:  Line 703:  
 GPa   GPa  
 Giga[https://en.wikipedia.org/wiki/Pascal_(unit) pascal]   Giga[https://en.wikipedia.org/wiki/Pascal_(unit) pascal]  
+    
+   mbar  
+   Milli[https://en.wikipedia.org/wiki/Bar_(unit) Bar], {{Version0.19}}  
+    
+   bar  
+   [https://en.wikipedia.org/wiki/Bar_(unit) Bar], {{Version0.19}}  
    
 uTorr   uTorr  
Line 522:  Line 720:  
    
 Torr   Torr  
−   [https://en.wikipedia.org/wiki/Torr Torr]  +   [https://en.wikipedia.org/wiki/Torr Torr]; 1 Torr = 133.32 Pa 
    
 psi   psi  
−   [https://en.wikipedia.org/wiki/Pounds_per_square_inch Poundforce per square inch]  +   [https://en.wikipedia.org/wiki/Pounds_per_square_inch Poundforce per square inch]; 1 psi = 6.895 kPa 
    
 ksi   ksi  
 Kilo[https://en.wikipedia.org/wiki/Pounds_per_square_inch poundforce per square inch]   Kilo[https://en.wikipedia.org/wiki/Pounds_per_square_inch poundforce per square inch]  
+    
+   Mpsi  
+   Mega[https://en.wikipedia.org/wiki/Pounds_per_square_inch poundforce per square inch], {{Version0.19}}  
}  }  
Line 564:  Line 765:  
 h   h  
 [https://en.wikipedia.org/wiki/Hour Hour]   [https://en.wikipedia.org/wiki/Hour Hour]  
+    
+   Hz (1/s)  
+   [https://en.wikipedia.org/wiki/Hertz Hertz], {{Version0.19}}  
+    
+   kHz  
+   Kilo[https://en.wikipedia.org/wiki/Hertz hertz], {{Version0.19}}  
+    
+   MHz  
+   Mega[https://en.wikipedia.org/wiki/Hertz hertz], {{Version0.19}}  
+    
+   GHz  
+   Giga[https://en.wikipedia.org/wiki/Hertz hertz], {{Version0.19}}  
+    
+   THz  
+   Tera[https://en.wikipedia.org/wiki/Hertz hertz], {{Version0.19}}  
}  }  
−  <!T:  +  <!T:50> 
−  +  Volume:  
{ class="wikitable floatright mwcollapsible mwcollapsed"  { class="wikitable floatright mwcollapsible mwcollapsed"  
!style="width: 33%;"Unit  !style="width: 33%;"Unit  
!style="width: 66%;"Description  !style="width: 66%;"Description  
    
−    +   ml 
−   [https://en.wikipedia.org/wiki/  +   Milli[https://en.wikipedia.org/wiki/Litre liter], {{Version0.19}} 
+    
+   l  
+   [https://en.wikipedia.org/wiki/Litre Liter]  
+    
+   cft  
+   Cubic[https://en.wikipedia.org/wiki/Foot_(unit) foot], {{Version0.19}}  
}  }  
−  <!T:  +  <!T:78> 
−  +  Special imperial units:  
{ class="wikitable floatright mwcollapsible mwcollapsed"  { class="wikitable floatright mwcollapsible mwcollapsed"  
!style="width: 33%;"Unit  !style="width: 33%;"Unit  
!style="width: 66%;"Description  !style="width: 66%;"Description  
    
−    +   mph 
−   [https://en.wikipedia.org/wiki/  +   [https://en.wikipedia.org/wiki/Miles_per_hour Miles per hour], {{Version0.19}} 
+    
+   sqft  
+   [https://en.wikipedia.org/wiki/Square_foot Square foot], {{Version0.19}}  
}  }  
Line 593:  Line 818:  
!style="width: 25%;"Alternative  !style="width: 25%;"Alternative  
    
−    +   °C 
−   [https://en.wikipedia.org/wiki/  +   [https://en.wikipedia.org/wiki/Celsius Celsius ] 
−    +   [°C] + 273.15 K 
    
−    +   °F 
−   [https://en.wikipedia.org/wiki/  +   [https://en.wikipedia.org/wiki/Fahrenheit Fahrenheit]; 
−    +   ([°F] + 459.67) × 5/9 
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
−  
    
 u   u  
Line 636:  Line 833:  
 [https://en.wikipedia.org/wiki/Unified_atomic_mass_unit Dalton]; alternative to the unit 'u'   [https://en.wikipedia.org/wiki/Unified_atomic_mass_unit Dalton]; alternative to the unit 'u'  
 1.66053906660e27 kg   1.66053906660e27 kg  
−  
−  
−  
−  
    
 sr   sr  
Line 653:  Line 846:  
 not directly   not directly  
    
−    +   px 
−    +   [https://en.wikipedia.org/wiki/Pixel Pixel] 
−    +   not directly 
+  }  
+  
+  ==Invalid characters and names== <!T:85>  
+  
+  <!T:86>  
+  The expression feature is very powerful but to achieve this power it has some limitations concerning some characters. To overcome this, FreeCAD offers to use labels and reference them instead of the object names. In labels you can use almost all special characters.  
+  
+  <!T:87>  
+  In cases where you cannot use a label, such as the name of a sketch's constraints, you must be aware what characters are not allowed.  
+  
+  ===Labels=== <!T:88>  
+  
+  <!T:89>  
+  For [[Object_name#Labellabels]] there are no invalid characters, however some characters need to be escaped:  
+  { class="wikitable floatright mwcollapsible mwuncollapsed"  
+  !style="width: 33%;"Characters  
+  !style="width: 66%;"Description  
+    
+   {{incode'}}, {{incode\}}, {{incode"}}  
+   Need to be escaped by adding {{incode\}} in front of them.  
+  }  
+  
+  <!T:90>  
+  For example, the label {{incodeSketch\002}} must be referenced as {{incode<<Sketch\\002>>}}.  
+  
+  ===Names=== <!T:91>  
+  
+  <!T:92>  
+  [[Object_name#NameNames]] of objects like dimensions, sketches, etc. may not have the characters or character sequences listed below, otherwise the name is invalid:  
+  
+  <!T:93>  
+  { class="wikitable floatright mwcollapsible mwuncollapsed"  
+  !style="width: 33%;"Characters / Character sequences  
+  !style="width: 66%;"Description  
+    
+   '''+''', '''''', '''*''', '''/''', '''^''', '''_''', '''<''', '''>''', '''(''', ''')''', '''{''', '''}''', '''[''', ''']''', '''.''', ''',''', '''='''  
+   Characters that are math operators or part of mathematical constructs  
+    
+   '''A''', '''kA''', '''mA''', '''MA''', '''C''', '''G''', '''F''', '''uF''', '''µF''', '''J''', '''K''', ''' ' ''', ''' ft ''', '''°''', and many more!  
+   Characters and character sequences that are [[Expressions#Unitsunits]]  
+    
+   '''#''', '''!''', '''?''', '''§''', '''$''', '''%''', '''&''', ''':''', ''';''', '''\''', '''<nowiki></nowiki>''', '''~''', '''∆''', '''¿''', and many more!  
+   Characters used as placeholder or to trigger special operations  
+    
+   '''pi''', '''e'''  
+   Mathematical constants  
+    
+   '''´''', '''`''', ''' ' ''', '''"'''  
+   Characters used for accents  
+    
+   space  
+   A space defines the end of a name and can therefore not be used  
}  }  
−  == Reference  +  <!T:95> 
+  For example, the following name is valid: {{incode<<Sketch>>.Constraints.T2üßµ@}}. While these are invalid names: {{incode<<Sketch>>.Constraints.test\result_2}} (\r means "carriage return") or {{incode<<Sketch>>.Constraints.mol}} (mol is a unit).  
+  
+  <!T:94>  
+  Since shorter names (especially if they have only one or two characters) can easily result in invalid names, consider using longer names and/or establishing a suitable naming convention.  
+  
+  == Reference to CAD data == <!T:12>  
<!T:13>  <!T:13>  
−  It is possible to use data from the model itself in an expression. To reference a property use  +  It is possible to use data from the model itself in an expression. To reference a property use{{incodeobject.property}}. If the property is a compound of fields, the individual fields can be accessed as {{incodeobject.property.field}}. 
<!T:14>  <!T:14>  
The following table shows some examples:  The following table shows some examples:  
{{{Prettytable}}  {{{Prettytable}}  
−  !CAD  +  !CAD data 
!Call in expression  !Call in expression  
!Result  !Result  
    
Parametric Length of a PartWorkbench Cube  Parametric Length of a PartWorkbench Cube  
−  Cube.Length  +  {{incodeCube.Length}} 
Length with units mm  Length with units mm  
    
Volume of the Cube  Volume of the Cube  
−  Cube.Shape.Volume  +  {{incodeCube.Shape.Volume}} 
−  Volume  +  Volume in mm³ without units 
    
Type of the Cubeshape  Type of the Cubeshape  
−  Cube.Shape.ShapeType  +  {{incodeCube.Shape.ShapeType}} 
String: Solid  String: Solid  
    
Label of the Cube  Label of the Cube  
−  Cube.Label  +  {{incodeCube.Label}} 
String: Label  String: Label  
    
xcoordinate of center of mass of the Cube  xcoordinate of center of mass of the Cube  
−  Cube.Shape.CenterOfMass.x  +  {{incodeCube.Shape.CenterOfMass.x}} 
xcoordinate in mm without units  xcoordinate in mm without units  
    
Value of constraint in a sketch  Value of constraint in a sketch  
−  Constraints.Width  +  {{incodeConstraints.Width}} 
−  Numeric value of the named constraint  +  Numeric value of the named constraint {{incodeWidth}} in the sketch, if the expression is used in the sketch itself. 
    
Value of constraint in a sketch  Value of constraint in a sketch  
−  MySketch.Constraints.Width  +  {{incodeMySketch.Constraints.Width}} 
−  Numeric value of the named constraint  +  Numeric value of the named constraint {{incodeWidth}} in the sketch, if the expression is used outside of the sketch. 
    
Value of a spreadsheet alias  Value of a spreadsheet alias  
−  Spreadsheet.Depth  +  {{incodeSpreadsheet.Depth}} 
−  Value of the alias  +  Value of the alias {{incodeDepth}} in the spreadsheet {{incodeSpreadsheet}} 
    
Value of a local property  Value of a local property  
−  Length  +  {{incodeLength}} 
−  Value of the Length property in e.g a Pad object, if the expression is used in e.g Length2 in the same object.  +  Value of the {{PropertyDataLength}} property in e.g a Pad object, if the expression is used in e.g {{PropertyDataLength2}} in the same object. 
}  }  
Line 715:  Line 966:  
<!T:21>  <!T:21>  
−  It is possible (with limitations) to define a Property of an object in your current document (".FCstd" file) by using an Expression to reference a Property of an object contained in a different document (".FCstd" file). For example, a cell in a spreadsheet or the Length of a Part Cube, etc. in one document can be defined by an Expression that references the X Placement value or another Property of an object contained in a different document.  +  It is possible (with limitations) to define a Property of an object in your current document (".FCstd" file) by using an Expression to reference a Property of an object contained in a different document (".FCstd" file). For example, a cell in a spreadsheet or the {{PropertyDataLength}} of a Part Cube, etc. in one document can be defined by an Expression that references the X Placement value or another Property of an object contained in a different document. 
<!T:22>  <!T:22>  
Line 721:  Line 972:  
<!T:23>  <!T:23>  
−  Once the master document with the spreadsheet is created and saved (named), it is safe to create dependent documents. For example, assuming you name the master document  +  Once the master document with the spreadsheet is created and saved (named), it is safe to create dependent documents. For example, assuming you name the master document {{incodemaster}}, the spreadsheet {{incodemodelConstants}}, and give a cell an aliasname {{incodeLength}}, you can then access the value as: 
−  +  <!T:65>  
−  master#modelConstants.Length  +  {{incodemaster#modelConstants.Length}} 
<!T:66>  <!T:66>  
−  Note that the master document must be loaded for the values in the master to be available to the dependent document.  +  '''Note:''' that the master document must be loaded for the values in the master to be available to the dependent document. 
<!T:24>  <!T:24>  
Line 738:  Line 989:  
<!T:18>  <!T:18>  
−  * The dependency graph is based on the relationship between document objects, not properties. This means that you cannot provide data to an object and query that same object for results. For example, even though there are no cyclic dependencies when the properties themselves are considered, you may not have an object which gets its dimensions from a spreadsheet and then display the volume of that object in the same spreadsheet. As a workaround  +  * The dependency graph is based on the relationship between document objects, not properties. This means that you cannot provide data to an object and query that same object for results. For example, even though there are no cyclic dependencies when the properties themselves are considered, you may not have an object which gets its dimensions from a spreadsheet and then display the volume of that object in the same spreadsheet. As a workaround use multiple spreadsheets, one to drive your model and the other for reporting. 
−  * The expression parser does not handle parentheses well, and is unable to properly parse some expressions. For example:  +  * The expression parser does not handle parentheses well, and is unable to properly parse some expressions. For example: {{incode<nowiki>=</nowiki> (A1 > A2) ? 1 : 0}} results in an error, while {{incode<nowiki>=</nowiki> A1 > A2 ? 1 : 0}} is accepted. The expression {{incode<nowiki>=</nowiki> 5 + ((A1>A2) ? 1 : 0)}} cannot be entered in any form. 
+  * As stated above, unfortunately, the integrated checker sometimes claims that a valid name doesn't exist. Continue typing anyway. When you have completed the full reference, the {{ButtonOK}} button will become active.  
* There is no expression manager implemented where all expressions in a document are listed, and can be created, deleted, queried, etc.  * There is no expression manager implemented where all expressions in a document are listed, and can be created, deleted, queried, etc.  
−  
* Open bugs/tickets for Expressions can be found in the [https://freecadweb.org/tracker/set_project.php?project_id=4;20 FreeCAD Bugtracker Expressions category]  * Open bugs/tickets for Expressions can be found in the [https://freecadweb.org/tracker/set_project.php?project_id=4;20 FreeCAD Bugtracker Expressions category]  
−  
−  
−  
−  
</translate>  </translate>  
+  {{Powerdocnavi{{#translation:}}}}  
+  [[Category:Spreadsheet{{#translation:}}]]  
{{clear}}  {{clear}} 
Latest revision as of 02:52, 26 March 2021
Overview
It is possible to define properties using mathematical expressions. In the GUI, spin boxes or input fields that are bound to properties contain a blue icon . Clicking on the icon or typing the equal sign = brings up the expression editor for that particular property.
A FreeCAD expression is a mathematical expression following notation for the standard mathematical operators and functions as described below. In addition, the expression may reference other properties, and also use conditionals. Numbers in an expression may have an optional unit attached to them.
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.
Operators and functions are unitaware, and require valid combinations of units, if supplied. For example, 2mm + 4mm
is a valid expression, while 2mm + 4
is not (the reason for this is that an expression like 1in + 4
will most likely be interpreted as 1in + 4in
by humans, but all units are converted to the SI system internally, and the system is not able to guess this). These units are currently recognized.
You can use predefined constants and functions.
Function Arguments
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.
Arguments may include references to cells in a spreadsheet. A cell reference consists of the cell's uppercase row letter followed by its column number, for example A1
. A cell may also be referenced by using the cell's alias instead, for example Spreadsheet.MyPartWidth
.
Referencing objects
You can reference an object by its DataName or by its DataLabel. In the case of a DataLabel, it must be enclosed in double <<
and >>
symbols, such as <<Label>>
.
You can reference any numerical property of an object. For example, to reference a Cylinder's height, you may use Cylinder.Height
or <<Long_name_of_cylinder>>.Height
.
To reference list objects, use <<object_label>>.list[list_index]
or object_name.list[list_index]
. If you want for example to reference a constraint in a sketch, use <<MySketch>>.Constraints[16]
. If you are in the same sketch you may omit its name and just use Constraints[16]
.
Note: The index starts with 0, therefore constraint 17 has the index 16.
For more information about referencing objects, see Reference to CAD_data.
Supported constants
The following constants are supported:
Constant  Description 

e  Euler's number 
pi  Pi 
Supported operators
The following operators are supported:
Operator  Description 

+  Addition 
  Subtraction 
*  Multiplication 
/  Floating point Division 
%  Remainder 
^  Exponentiation 
Supported functions
General mathematical functions
The mathematical functions listed below are available.
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)
. Expressions in degrees can use either deg
or °
, e.g. 360deg  atan2(3; 4)
or 360°  atan2(3; 4)
. If an expression is without units and needs to be converted to degrees or radians for compatibility, multiply by 1 deg
, 1 °
or 1 rad
as appropriate, e.g. (360  X) * 1deg
; (360  X) * 1°
; (0.5 + pi / 2) * 1rad
.
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 in the direction of zero  all 
Statistical / aggregate functions
Aggregate functions take one or more arguments.
Individual arguments to aggregate functions may consist of ranges of cells. A range of cells is expressed as two cell references separated by a colon :
, for example average(B1:B8)
or sum(A1:A4; B1:B4)
.
The cell references may also use cell aliases, for example average(StartTemp:EndTemp)
introduced in version 0.19.
These aggregate functions are supported:
Function  Description  Value range 

average(a; b; c; ...)  Average value of the arguments; same as sum(a; b; c; ...) / count(a; b; c; ...)  all 
count(a; b; c; ...)  Count of the arguments; typically used for cell ranges  all 
max(a; b; c; ...)  Maximum value of the arguments  all 
min(a; b; c; ...)  Minimum value of the arguments  all 
stddev(a; b; c; ...)  Standard deviation of the values of the arguments  all 
sum(a; b; c; ...)  Sum of the values of the arguments; typically used for cell ranges  all 
Conditional expressions
Conditional expressions are of the form condition ? resultTrue : resultFalse
. The condition is defined as an expression that evaluates to either 0
(false) or nonzero (true).
Note that enclosing the conditional expression in parentheses is currently considered an error. version 0.19 and below
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 
Units
Units can be used directly 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³.
If you have a variable whose name is that of a unit you must put the variable between << >>
to prevent it from being recognized as a unit. For example if you have the dimension Sketch.Constraints.A
it would be recognized as the unit ampere. Therefore you must write it in the expression as Sketch.Constraints.<<A>>
.
The following units are recognized by the expression parser:
Amount of substance:
Unit  Description 

mmol  Millimole 
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 
Electrical capacitance:
Unit  Description 

pF  Picofarad, introduced in version 0.19 
nF  Nanofarad, introduced in version 0.19 
uF  Microfarad; alternative to the unit µF, introduced in version 0.19 
µF  Microfarad; alternative to the unit uF, introduced in version 0.19 
mF  Millifarad, introduced in version 0.19 
F  Farad; 1 F = 1 s^4·A^2/m^2/kg, introduced in version 0.19 
Electrical conductance:
Unit  Description 

uS  Microsiemens; alternative to the unit µS, introduced in version 0.19 
µS  Microsiemens; alternative to the unit uS, introduced in version 0.19 
mS  Millisiemens, introduced in version 0.19 
S  Siemens; 1 S = 1 s^3·A^2/kg/m^2, introduced in version 0.19 
kS  Kilosiemens, introduced in version 0.20 
MS  Megasiemens, introduced in version 0.20 
Electrical inductance:
Unit  Description 

nH  Nanohenry, introduced in version 0.19 
uH  Microhenry; alternative to the unit µH, introduced in version 0.19 
µH  Microhenry; alternative to the unit uH, introduced in version 0.19 
mH  Millihenry, introduced in version 0.19 
H  Henry; 1 H = 1 kg·m^2/s^2/A^2, introduced in version 0.19 
Electrical resistance:
Unit  Description 

Ohm  Ohm; 1 Ohm = 1 kg·m^2/s^3/A^2, introduced in version 0.19 
kOhm  Kiloohm, introduced in version 0.19 
MOhm  Megaohm, introduced in version 0.19 
Electric charge:
Unit  Description 

C  Coulomb; 1 C = 1 A·s, introduced in version 0.19 
Electric potential:
Unit  Description 

mV  Millivolt 
V  Volt 
kV  Kilovolt 
Energy / work:
Unit  Description 

mJ  Millijoule 
J  Joule 
kJ  Kilojoule, introduced in version 0.19 
eV  Electronvolt; 1 ev = 1.602176634e19 J, introduced in version 0.19 
keV  Kiloelectronvolt, introduced in version 0.19 
MeV  Megaelectronvolt, introduced in version 0.19 
kWh  Kilowatt hour; 1 kWh = 3.6e6 J, introduced in version 0.19 
Ws  Watt second; alternative to the unit Joule 
VAs  Voltamperesecond; alternative to the unit Joule 
CV  Coulombvolt; alternative to the unit Joule 
cal  Calorie; 1 cal = 4.184 J, introduced in version 0.19 
kcal  Kilocalorie, introduced in version 0.19 
Force:
Unit  Description 

mN  Millinewton 
N  Newton 
kN  Kilonewton 
MN  Meganewton 
lbf  Pound of force 
Length:
Unit  Description 

nm  Nanometer 
mu  Micrometer; alternative to the unit µm 
µm  Micrometer; alternative to the unit mu 
mm  Millimeter 
cm  Centimeter 
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 
Magnetic field strength:
Unit  Description 

Oe  Oersted; 1 Oe = 79.57747 A/m, introduced in version 0.19 
Magnetic flux:
Unit  Description 

Wb  Weber; 1 Wb = 1 kg*m^2/s^2/A, introduced in version 0.19 
Magnetic flux density:
Unit  Description 

G  Gauss; 1 G = 1 e4 T, introduced in version 0.19 
T  Tesla; 1 T = 1 kg/s^2/A, introduced in version 0.19 
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  Description 

W  Watt 
kW  Kilowatt, introduced in version 0.19 
VA  Voltampere 
Pressure:
Unit  Description 

Pa  Pascal 
kPa  Kilopascal 
MPa  Megapascal 
GPa  Gigapascal 
mbar  MilliBar, introduced in version 0.19 
bar  Bar, introduced in version 0.19 
uTorr  Microtorr; alternative to the unit µTorr 
µTorr  Microtorr; alternative to the unit uTorr 
mTorr  Millitorr 
Torr  Torr; 1 Torr = 133.32 Pa 
psi  Poundforce per square inch; 1 psi = 6.895 kPa 
ksi  Kilopoundforce per square inch 
Mpsi  Megapoundforce per square inch, introduced in version 0.19 
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 
Hz (1/s)  Hertz, introduced in version 0.19 
kHz  Kilohertz, introduced in version 0.19 
MHz  Megahertz, introduced in version 0.19 
GHz  Gigahertz, introduced in version 0.19 
THz  Terahertz, introduced in version 0.19 
Volume:
Unit  Description 

ml  Milliliter, introduced in version 0.19 
l  Liter 
cft  Cubicfoot, introduced in version 0.19 
Special imperial units:
Unit  Description 

mph  Miles per hour, introduced in version 0.19 
sqft  Square foot, introduced in version 0.19 
The following commonly used units are not yet supported:
Unit  Description  Alternative 

°C  Celsius  [°C] + 273.15 K 
°F  Fahrenheit;  ([°F] + 459.67) × 5/9 
u  Atomic mass unit; alternative to the unit 'Da'  1.66053906660e27 kg 
Da  Dalton; alternative to the unit 'u'  1.66053906660e27 kg 
sr  Steradian  not directly 
lm  Lumen  not directly 
lx  Lux  not directly 
px  Pixel  not directly 
Invalid characters and names
The expression feature is very powerful but to achieve this power it has some limitations concerning some characters. To overcome this, FreeCAD offers to use labels and reference them instead of the object names. In labels you can use almost all special characters.
In cases where you cannot use a label, such as the name of a sketch's constraints, you must be aware what characters are not allowed.
Labels
For labels there are no invalid characters, however some characters need to be escaped:
Characters  Description 

' , \ , "

Need to be escaped by adding \ in front of them.

For example, the label Sketch\002
must be referenced as <<Sketch\\002>>
.
Names
Names of objects like dimensions, sketches, etc. may not have the characters or character sequences listed below, otherwise the name is invalid:
Characters / Character sequences  Description 

+, , *, /, ^, _, <, >, (, ), {, }, [, ], ., ,, =  Characters that are math operators or part of mathematical constructs 
A, kA, mA, MA, C, G, F, uF, µF, J, K, ' , ft , °, and many more!  Characters and character sequences that are units 
#, !, ?, §, $, %, &, :, ;, \, , ~, ∆, ¿, and many more!  Characters used as placeholder or to trigger special operations 
pi, e  Mathematical constants 
´, `, ' , "  Characters used for accents 
space  A space defines the end of a name and can therefore not be used 
For example, the following name is valid: <<Sketch>>.Constraints.T2üßµ@
. While these are invalid names: <<Sketch>>.Constraints.test\result_2
(\r means "carriage return") or <<Sketch>>.Constraints.mol
(mol is a unit).
Since shorter names (especially if they have only one or two characters) can easily result in invalid names, consider using longer names and/or establishing a suitable naming convention.
Reference to CAD data
It is possible to use data from the model itself in an expression. To reference a property useobject.property
. If the property is a compound of fields, the individual fields can be accessed as object.property.field
.
The following table shows some examples:
CAD data  Call in expression  Result 

Parametric Length of a PartWorkbench Cube  Cube.Length

Length with units mm 
Volume of the Cube  Cube.Shape.Volume

Volume in mm³ without units 
Type of the Cubeshape  Cube.Shape.ShapeType

String: Solid 
Label of the Cube  Cube.Label

String: Label 
xcoordinate of center of mass of the Cube  Cube.Shape.CenterOfMass.x

xcoordinate in mm without units 
Value of constraint in a sketch  Constraints.Width

Numeric value of the named constraint Width in the sketch, if the expression is used in the sketch itself.

Value of constraint in a sketch  MySketch.Constraints.Width

Numeric value of the named constraint Width in the sketch, if the expression is used outside of the sketch.

Value of a spreadsheet alias  Spreadsheet.Depth

Value of the alias Depth in the spreadsheet Spreadsheet

Value of a local property  Length

Value of the DataLength property in e.g a Pad object, if the expression is used in e.g DataLength2 in the same object. 
Documentwide 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 (rightclick on cell). Then they can be accessed from any expression just as any other object property.
Crossdocument linking
It is possible (with limitations) to define a Property of an object in your current document (".FCstd" file) by using an Expression to reference a Property of an object contained in a different document (".FCstd" file). For example, a cell in a spreadsheet or the DataLength of a Part Cube, etc. in one document can be defined by an Expression that references the X Placement value or another Property of an object contained in a different document.
A document's name is used to reference it from other documents. When saving a document the first time, you choose a file name; this is usually different from the initial default "Unnamed1" (or its translated equivalent). To prevent links being lost when the master document is renamed upon saving, it is recommended that you first create the master document, create a spreadsheet inside it, and save it. Subsequently, you can still make changes to the file and its spreadsheet but you should not rename it.
Once the master document with the spreadsheet is created and saved (named), it is safe to create dependent documents. For example, assuming you name the master document master
, the spreadsheet modelConstants
, and give a cell an aliasname Length
, you can then access the value as:
master#modelConstants.Length
Note: that the master document must be loaded for the values in the master to be available to the dependent document.
Unfortunately, the integrated checker sometimes claims that a valid name doesn't exist. Continue typing anyway. When you have completed the full reference, the OK button will become active.
Of course, it's up to you to load the corresponding documents later when you want to change anything.
Known issues / remaining tasks
 The dependency graph is based on the relationship between document objects, not properties. This means that you cannot provide data to an object and query that same object for results. For example, even though there are no cyclic dependencies when the properties themselves are considered, you may not have an object which gets its dimensions from a spreadsheet and then display the volume of that object in the same spreadsheet. As a workaround use multiple spreadsheets, one to drive your model and the other for reporting.
 The expression parser does not handle parentheses well, and is unable to properly parse some expressions. For example:
= (A1 > A2) ? 1 : 0
results in an error, while= A1 > A2 ? 1 : 0
is accepted. The expression= 5 + ((A1>A2) ? 1 : 0)
cannot be entered in any form.  As stated above, unfortunately, the integrated checker sometimes claims that a valid name doesn't exist. Continue typing anyway. When you have completed the full reference, the OK button will become active.
 There is no expression manager implemented where all expressions in a document are listed, and can be created, deleted, queried, etc.
 Open bugs/tickets for Expressions can be found in the FreeCAD Bugtracker Expressions category
 FreeCAD scripting: Python, Introduction to Python, Python scripting tutorial, FreeCAD Scripting Basics
 Modules: Builtin modules, Units, Quantity
 Workbenches: Workbench creation, Gui Commands, Commands, Installing more workbenches
 Meshes and Parts: Mesh Scripting, Topological data scripting, Mesh to Part, PythonOCC
 Parametric objects: Scripted objects, Viewproviders (Custom icon in tree view)
 Scenegraph: Coin (Inventor) scenegraph, Pivy
 Graphical interface: Interface creation, Interface creation with UI files, Interface creation completely in Python (1, 2, 3, 4, 5), PySide, PySide examples beginner, intermediate, advanced
 Macros: Macros, How to install macros
 Embedding: Embedding FreeCAD, Embedding FreeCADGui
 Other: Expressions, Code snippets, Line drawing function, FreeCAD vector math library (deprecated)
 Hubs: User hub, Power users hub, Developer hub