Variables can be declared using the let
keyword. A temporary variable does not persist as a parameter after the rule execution is finished. A local variable must be attributed an initial value.
The variable can be:
- A parameter (literal, lists, isolated wireframe geometry). In this case, the local variable is a value.
let x (type)
x = parameter
The parameter value is attributed to x. If you modify x, the parameter value is not modified.
let x(real)
x = Real.1
x = 0.5
/*Real.1 is not modified*/
Note:
You can declare more than one variable in a single line: let <var1>,<var2>,<var3> (Type)
(only on the client) : let a,b,c,d(Integer)
Let l(List)
a = 1
b = 2
c = 3
d = 4
l.Append(a)
l.Append(b)
l.Append(c)
l.Append(d)
Notify(“#”,l[2])
l[2] = 10
Notify(“#”,l[2])
- A pointer. The type has to be indicated.
let H(Hole)
H=Hole.1
H.Diameter = 20mm
/*Hole.1 is modified*/
Variables Declaration
let
Keyword- The
let
keyword can be used at the beginning of a script. Variables can now be declared anywhere in the script using the let
keyword enabling you to declare variables when needed (on the client only). Variables have a scope. This means that a variable declared within a block can only be used within this block.let a(Integer)
[...]
if a == 2
{
Let b(Integer) // b can be used in this block
b = a + 10
}
// b cannot be used here
Temporary variables can be declared at the beginning of the script using
the let
keyword. A temporary variable does not
persist as a parameter after the rule execution is finished.
let x = 5 mm
if PartBody\Hole.1\Diameter > x
{
PartBody\Hole.1\Activity = false
}
For non digital values, the type must be indicated:
let S(Surface)
S= split (...,...)
Temporary variables must be declared at the beginning of the rule before any conditional instruction is specified.
let S1(Surface)
let S2(Surface)
let S3(Surface)
S1 = Split ...
S2 = ...
S3 = ...
let
enables you to initialize values with constants and not with formulas: let rmax = Relations.A\DesignTable.1\Sheet > RowsNb
is not correct whereas Let rmax = 0
Rmax = Relations.A\DesignTable.1\Sheet > RowsNb
is correct.
set
keyword- The
set
keyword lets you set a
variable of a given type and directly enter the attribute to read and/or write its
characteristics. /*You can start from an object in a variable x and want to manipulate it as a Hole.
To do so, use the set keyword to indicate that you want to manipulate the object as a Hole*/
let y(Hole)
set y = x
if (y <> NULL) Message ("Hole diameter is #",y.Diameter)
When setting a variable, the value type must be a subtype of the variable creation type. It is impossible to change the type of a variable after its creation, except in the following cases:
- You use the
set
keyword that lets you affect a variable without checking the type. If the member object located at the right of the affectation also supports the type of the variable located at the left, the affectation is performed. If not, the variable is set to NULL
. let C1(Curve)
let C2(Curve)
C1=intersect(PartBody\Extrude.1,'xy plane')
C2=intersect(PartBody\Extrude.2,'xy Plane')
PartBody\Line.2 = C1
PartBody\Line.3 = C2
/*The affectation does not work because you are trying to affect a line to a curve. */
- The
NULL
keyword is a constant. When this constant is passed as an argument of a function, no check is performed on the type thus enabling you to set any variable to NULL or to compare a variable with NULL to find out if it is unset. pointOncurve (C, 10mm, NULL)
The return type of some methods is UndefinedType
. In such a case, you can valuate any variable with this function return. x = List.GetItem
- When you use variables of
enumerate
type (for example V_NatureEnum), the enumerated constants are strings. To compare or valuate an enumerated variable with one of its enum values, use the corresponding string. let s(String)
let v(V_NatureEnum)
v = x.V_nature
s = x.V_nature /* automatic cast */
if (v == "Specification" /* automatic cast */)
Message ("Specification")
Note:
The set
keyword is also a conversion operator. It lets you switch between types and checks if the variable supports the destination type. If not, NULL is returned.