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.
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:
- From the main menu, select Add > Variables.
- 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.
- 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.
- 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:
- Open the input field where you want to define a value.
- Enter a numerical value for the variable.
- Select Insert Variable
beside the input field.
- Choose “Create [variable_default_name] = [value]” to confirm the variable creation.
Example: Entering 4 for a length will display “Create length1 = 4”. - 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:
- Open the History Sidebar.
- Locate the variable you want to update.
- Right-click or long-tap on the variable name.
- Select Rename and Update References.
- Enter a new variable name and confirm.
To update only the value:
- Tap or hover over the value in the History Sidebar.
- 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:
- Select Insert Variable
beside the input field.
- 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 support basic arithmetic operations and can be combined with variables to automate design modifications.
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:
- Open the input field.
- Enter the expression directly in the input field.
- Press Enter to apply the calculated value.
- 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 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
- 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.