Parameters and rules
Parameters
Each feature value in Meridian is a named parameter. For example, the distance of the first extrude is Extrude1_Distance. You can also add user parameters.
To see and change the parameters, select Tools > Parameters (Data panel).
The Parameters window
| Item | What it does |
|---|---|
| Search | Shows only the parameters that have the text in their name. |
| User parameters only | Hides the parameters of the features. |
| Show unused | Also shows the feature parameters that the options of the feature do not use, for example the head size of a simple hole. It is off by default. |
| Add | Adds a user parameter. Select the unit of the new parameter first. |
| Remove | Removes the selected parameter. |
The table has the columns Name, Expression, Value, Unit, Kind and Comment. An expression that is not a plain number shows an fx badge.
Add a user parameter
- Select Tools > Parameters.
- Select the unit of the new parameter.
- Click Add.
- Type a name and an expression.
- Use the name in a feature value or in other expressions.
Expressions
A parameter value can be a number or an expression.
| Example | Result |
|---|---|
25 |
25 in the document unit. In a millimeter document, this is 25 mm. In an inch document, this is 25 in. |
2 in |
2 inches (50.8 mm). |
120/2 |
Meridian keeps the value 60 mm. |
Thickness * 2 |
Two times the parameter Thickness. |
Sqrt(Width ^ 2 + Height ^ 2) |
The diagonal of a rectangle. |
Units
You can write these units after a number:
| Unit | Meaning |
|---|---|
mm, cm, m |
Millimeters, centimeters, meters |
in |
Inches |
mil |
Thousandths of an inch |
um or µm |
Micrometers |
deg |
Degrees |
The case of the letters is not important: MM and mm are the same. A number without a unit uses the unit of the document. Angles are in degrees.
Operators
| Operator | Meaning |
|---|---|
+ - * / |
Add, subtract, multiply, divide |
\ |
Integer division (Meridian rounds both values, divides, and removes the fraction) |
^ |
Power |
Mod |
Remainder |
Functions
| Group | Functions |
|---|---|
| Trigonometry | Sin, Cos, Tan, Asin, Acos, Atan (Atn is the same as Atan), Atan2 |
| Trigonometry in degrees | SinD, CosD, TanD, AsinD, AcosD, AtanD, Atan2D |
| Angle conversion | Radians, Degrees |
| Rounding | Round, Ceiling (or Ceil), Floor, Int, Fix |
| Other | Sqrt, Abs, Min, Max, Exp, Log, Log10, Sign |
| Constant | PI |
Notes:
Round(x)rounds to a whole number.Round(x, n)keepsndecimal places (0 to 15). A half rounds away from zero:Round(2.5)is 3.Introunds down, asFloordoes.Fixremoves the fraction:Fix(-2.7)is -2.MinandMaxtake one or more values.- You can also write
Math.Sqrt,Math.PIand the other functions withMath.in front.
In a parameter expression, Meridian knows when a value is an angle. Thus Sin, Cos and Tan of an angle parameter use its degrees. A plain number uses radians. In a rule, these functions always use radians. Refer to Angles in rules.
References
- Use a parameter by its name, for example
Width. You can also writeParam("Width")orParameters("Width"). - Use a document property with
Property("name")orProperties("name"). - If you type a name that does not exist, Meridian shows "Unknown parameter 'X'. Did you mean 'Y'?" when a similar name exists.
Rules for expressions
- A parameter expression must give a number. If it gives text, Meridian shows "The expression gives text. Enter a number."
- The result must have the correct kind of unit. If you enter an area for a length, Meridian shows "The expression gives an area. Enter a length."
- A number without a unit takes the kind of unit that the parameter needs.
- A count, for example the count of a pattern, must be a whole number from 1 to 2500.
Meridian Rules
A rule is a short program that changes parameters and properties. The language is similar to Visual Basic. The rules are saved in the document.
Write and run a rule
- Select Tools > Rules (Rules panel).
- Click Add to make a new rule. Type a Rule name.
- Type the rule in the editor.
- Click Check to find syntax errors.
- Click Save Rules to keep the rules in the document.
- Click Run.
To run the selected rule without the Rules window, select Tools > Run Rule. To delete a rule, select it and click Remove.
When you click Run in the Rules window, the status shows "The rule ran. The model is updated." If there are warnings, the status also shows "The log shows N warnings." The log shows all of the warnings.
When you use Tools > Run Rule and there are warnings, a message shows "Rule1 ran with N warnings." and up to 3 of the warnings. To see all of the warnings, run the rule in the Rules window.
Example
' Comments start with ' or //
Extrude1_Distance = 35
Param("BoltPattern1_Count") = Round(Extrude1_Distance / 5)
Properties("Revision Number") = "R1"
Dim ratio = 0.5
If Extrude1_Distance >= 30 And Properties("Material") <> "Aluminum" Then
EdgeFillet1_Radius = 4
ElseIf Extrude1_Distance < 10 Then
EdgeFillet1_Radius = 1
Else
EdgeFillet1_Radius = 2
End If
Statements
| Statement | What it does |
|---|---|
Name = value |
Sets a parameter. |
Param("name") = value |
Sets a parameter. Parameters("name") is the same. |
Properties("name") = "text" |
Sets a document property. Property("name") is the same. |
Dim name = value |
Makes a variable that only the rule uses. Dim name As Double is also accepted. A Dim needs a type or a start value. |
If ... Then ... ElseIf ... Else ... End If |
Runs lines only when a condition is true. A short If can be on one line. |
More operators in rules
- Text:
&joins two texts.CStrchanges a number to text.CDblchanges text to a number. - Comparison:
=,<>,<,>,<=,>=. - Logic:
Not,And,Or,Xor,AndAlso,OrElse. TrueandFalse.
Angles in rules
In a rule, Sin, Cos and Tan use radians. The unit deg does not change a value to radians. Thus Sin(30 deg) is the sine of 30 radians. For degrees, use SinD, CosD and TanD. For example, SinD(30) is 0.5. You can also use Radians(x) and Degrees(x).
How a rule runs
- A rule runs as one change. One Undo removes all of the changes of the rule.
- If an error occurs, the rule stops. Meridian shows the line of the error and removes all of the changes that the rule made.
- Errors include syntax errors, unknown names, wrong types, division by zero, and values that the model does not accept.
- If a rule puts a number in a parameter that had an expression, Meridian gives a warning: "The rule replaced the expression '...' of NAME with the value V. To get the expression again, use Undo."
Run a rule from the command line
meridian rule part.mpart myrule.txt --save
meridian rule part.mpart -e "Extrude1_Distance = 40" --out part-40.mpart
If the part does not regenerate after the rule, the command lists the features with errors, does not save, and stops with exit code 1. Refer to Command line.
An AI agent can run a rule with the MCP tool run_rule. Refer to MCP server for AI agents.