Variables and expressions

You can use variables and expressions in Shapr3D to define and calculate values dynamically in input fields. Expressions let you perform calculations directly within numerical fields, while variables allow you to assign names to values and reuse them across multiple parameters. This makes it easy to adjust dimensions, constraints, and transformations without manually updating each value.

Note: Expressions only support decimal format. Fractional input (e.g., 2’-1 1/2”) is not accepted. You can use expressions to write imperial fractional values (e.g., 2 ft + (1 + 1/2) in).

Variables

Variables let you assign names to numerical values, making it easier to reuse them across multiple parameters. When a variable is updated, all linked values automatically adjust, streamlining modifications without manually updating each instance.

Created variables appear in the History Sidebar, where you can rename them and update their references.

Variable naming rules

When you create variables, follow these guidelines:

  • Variable names can include English alphanumeric characters (A–Z, a–z), underscores (_), and digits (0–9).
  • Variable names must not start with a digit.
  • Variable names must be no longer than 100 characters.
  • Variable names must not start with double underscores (starting with a single underscore is allowed).

Create and define a variable

You can create a variable in two ways: directly from an input field or from the Variables panel. Once created, variables are automatically added to the History sidebar, where you can rename them, update their values, and manage their references.

From the Variable panel

You can create variables from the Variables panel. The panel stays open, allowing you to define multiple variables without reopening it each time.

To create variables from the Variables panel:

  1. From the main menu, select Add > Variables.
  2. Choose the variable type:
    • Length – Distance-based values (e.g., mm, cm, in, ft).
    • Angle – Angular values (e.g., degrees).
    • Number – Numerical values for general calculations.
  3. In the left field, enter a variable name, and in the right field, enter the numerical value to assign, following the format Variable Name = Numerical Value.
  4. To finish, select Create Variable.

From the input field

You can create a variable directly from any input field to store and reuse values across multiple parameters.

To create a variable from the input field:

  1. Open the input field where you want to define a value.
  2. Enter a numerical value for the variable.
  3. Select Insert Variable icon-add-variable.png beside the input field.
  4. Choose “Create [variable_default_name] = [value]” to confirm the variable creation.
    Example: Entering 4 for a length will display “Create length1 = 4”.
  5. Check the History Sidebar to see the created variable.

History updates

Created variables appear in the History Sidebar with default variable names. From there, you can rename variables and update their references as needed.

To rename and update references for a variable:

  1. Open the History Sidebar.
  2. Locate the variable you want to update.
  3. Right-click or long-tap on the variable name.
  4. Select Rename and Update References.
  5. Enter a new variable name and confirm.

To update only the value:

  1. Tap or hover over the value in the History Sidebar.
  2. Enter a new value in the input field.

Using variables in expressions

Variables you create and define can be used in expressions to replace fixed values, making it easier to adjust dimensions and constraints dynamically. When updated, all linked values adjust automatically, eliminating manual recalculations. Variables also work with arithmetic operations and unit conversions like regular numerical values, making them useful for parametric design.

Add a variable to an expression

To add variables to expressions:

  1. Select Insert Variable icon-add-variable.png beside the input field.
  2. Choose the variable from the list to insert it into the expression.

Examples of variables in expressions

  Scenario   Expression   Defined Variable   Result  

 

Adjusting box height based on width

 

box_height = box_width * 2   box_width = 50 mm   box_height = 100 mm  

 

Centering a hole inside a circular part

 

hole_offset = outer_diameter / 2   outer_diameter = 40 mm   hole_offset = 20 mm  

 

Scaling a feature dynamically

 

scaled_length = base_length * 1.5   base_length = 80 mm   scaled_length = 120 mm  

 

Expressions

You can use expressions to perform calculations directly within input fields to define numerical values dynamically. Expressions in Shapr3D support both basic arithmetic and advanced built-in functions. You can enter expressions in most parameter fields and define them with operators, variables, and units. You can also toggle a numpad for easier access to common operators and units. Once applied, expressions are automatically reformatted to maintain consistency.

Entering expressions

Expressions can be used in any numerical input field that appears when defining values, including distances, angles, quantities, sketch dimension constraints, and transformations.

To enter an expression:

  1. Open the input field.
  2. Enter the expression directly in the input field.
  3. Press Enter to apply the calculated value.
  4. To use a variable, select the variable icon to insert it into the expression.

Supported operations

Expressions support basic arithmetic operations and variables can also be used within expressions for dynamic calculations:

  • Addition (+): 10 + 5 → 15
  • Subtraction (-): 20 - 4 → 16
  • Multiplication (*): 8 * 3 → 24
  • Division (/): 12 / 3 → 4
  • Parentheses (): (5 + 3) * 2 → 16 (used to control order of operations)

Supported functions

Shapr3D supports a wide range of built-in functions that can be used within expressions to perform mathematical and trigonometric operations as shown in the table below. These functions make it easier to define dynamic relationships and automate calculations across your design.

Before using functions, review these rules:

  • Function names are case-sensitive.
  • Functions are evaluated using Parasolid’s precision tolerance of 1e-8. For example, ceil(1e-10) will return 0, since the value is interpreted as zero within that range. Similarly, functions like floor() and sign() may round differently depending on how close values are to whole numbers under this precision.

To learn how values are calculated and prioritized, check the Order of operations and Handling errors sections.

  Function Description Aliases  
  sqrt(n) Returns the square root of n    
  sign(n) Returns 1 if positive, 0 if zero, -1 if negative sgn  
  floor(n) Largest integer not greater than n    
  ceil(n) Smallest integer not less than n ceiling  
  round(n) Nearest integer to n    
  abs(n) Returns the absolute value of n absolute  
  mod(a, b) Remainder of a divided by b remainder  
  min(a, b) Returns the lesser of a or b minimum  
  max(a, b) Returns the greater of a or b maximum  
  avg(a, b) Returns the average of a and b average, mean  
  sin(x) Sine of angle x    
  cos(x) Cosine of angle x    
  tan(x) Tangent of angle x tg  
  cotan(x) Cotangent of angle x cot, ctg  
  sec(x) Secant of angle x    
  cosec(x) Cosecant of angle x csc  
  arcsin(x) Arcsine of x asin  
  arccos(x) Arccosine of x acos  
  arctan(x) Arctangent of x atan  
  arctan2(x, y) 2-argument arctangent of y and x atan2  
  arccotan(x) Arccotangent of x acot, actg  
  arcsec(x) Arcsecant of x asec  
  arccosec(x) Arccosecant of x acsc  

 

Important

For complex expressions—such as those using operators, variables, functions, or units—use decimal points (.) for numbers. Commas aren’t supported in function calls or unit definitions.

Supported units

Expressions and variables allow unit conversions by specifying different units within calculations.

Examples:

  • 5 mm + 2 cm → 25 mm
  • 3 in * 2 → 6 in
  • 10 mm / 2 → 5 mm

If no unit is specified, the workspace default unit is applied.

Length units

  • Millimeter: mm, millimeter(s)
  • Centimeter: cm, centimeter(s)
  • Meter: m, meter(s)
  • Inch: in, inch(es)
  • Foot: ft, foot, feet

Angle units

  • Degrees: deg, degree(s)

Unit rules

  • Expressions can involve multi-dimensional units (like area or volume), but input fields only accept single-dimension results (length, angle, or scalar). For example, multiplying two lengths gives an area, but dividing that by another length brings it back to a valid length value.
  • If you mix different length units (e.g., 10 mm + 1 in), the result is automatically converted based on the active workspace unit.
  • Angle units must be explicitly defined (e.g., 30 deg instead of 30°).
  • You can use expressions to write imperial fractional values (e.g., 2 ft + (1 + 1/2) in).
    Note: Expressions do not support fractional input (1 1/2 in is invalid; instead, use 1.5 in).

Order of operations

Expressions follow the standard mathematical order:

  • Parentheses ()
  • Multiplication * and Division /
  • Addition + and Subtraction -

Example: 10 + 2 * 3 results in 16, while (10 + 2) * 3 results in 36.

Handling errors

If an expression contains invalid characters or incorrect syntax, an error message appears.

  • If an expression contains invalid characters or incorrect syntax, an error message appears.
  • Ensure all expressions use supported operators and follow the correct format.
  • Mixed unit types (e.g., 5 mm + 3 deg) are not allowed.

Read more

For basic numerical input and calculations, visit Defining and calculating numerical values.

Return to top
Was this article helpful?
9 out of 18 found this helpful

Topics