List

List methods are used to manage lists of parameters, pads ... They enable you to create lists, add items to the list, remove items from the list, retrieve values from the list, move elements of the list to another position, filter, and to copy the content of a list into another one. These functions are available in the Formula, the Rule and in the Action editors.

Methods Available in All Editors

Some methods are available in all Knowledge editors.

List -> Size () : Integer

Method used to return the number of items contained in the list.

List -> GetItem (Index: Integer) :ObjectType

Method used to retrieve a value/item from the list. (Index from 1).

Important: By default, GetItem can return any kind of object. As a consequence, it is mandatory to put the result of the GetItem method in a local variable. You have to perform this in order to:
  • test if the variable is NULL i.e. the object is not of the expected type
  • avoid uncertainties. For example, if you write length(List.GetItem(i)), the system can choose the length function either on curves or on edges

List -> Sum () : Real

Computes the sum of the items contained in the list. Available for integers and real numbers only.

Example

let L1(List) let r=0.0... r=L1->Sum()

List -> IndexOf (Element: ObjectType, StartIndex:Integer):Integer

Returns the first index of a list item. The item is searched for from the start index.

Copy (List: List) : List

Function used to copy the content of a list and paste it in another list.

List (Next: ObjectType, ...): List

Function used to create a list.

Example

let L1(List) L1= List(Item1,Item2,Item3)

Methods Available in the Action and the Reaction Editors Only

Some methods can only be used in the Action and theReaction editors.

List -> AddItem (Object: Objecttype, Index: Integer):VoidType

Method used to add an item to the list. If the index is equal to 0, the new item is added at the end of the list. If the index is equal to 1, the new item is inserted into the list at the location indicated by the index, meaning that the existing item is replaced with the new one and is therefore removed from the list. It is recommended to use the InsertItem method.

Example

let list (List) list -> AddItem(PartBody\Hole.2 ,1) list -> AddItem(PartBody\Hole.3 ,2) Message("#",list.Size())

List -> InsertItem (Object:ObjectType, Index: Integer): VoidType

Method used to insert an item into the list. Where:


  • Object is the object to insert into the list.
  • Index is the location of the object to be inserted into the list (Starts at 1)

List -> Append (Object:ObjectType)

Method used to add an item at the end of the list. Where:


  • Object is the object to insert into the list.

List -> SetItem (Object:ObjectType, Index: Integer): VoidType

Method used to replace an item in the list. Where:


  • Object is the object to insert into the list.
  • Index is the location of the object to be replaced in the list. In this case, the object to be replaced is deleted. Index starts at 1

List -> RemoveItem (Index: Integer) :VoidType

Method used to remove an item from the list.Index is the location of the object to be removed in the list. The index starts at 1.

List -> RemoveAll(): VoidType

Method used to empty the list.

List -> ReorderItem (Current: Integer, Target: Integer ) :ObjectType

Method used to move an element of the list referenced by its position to a new position. The position starts at 1.

List -> Compute(Operation: String, Type: String, Expression: String, Result: out UndefinedType): VoidType

Function used to compute the result of an operation performed all the elements of the list. It is available for Actions, Reactions and in Knowledge Expert.

1. There are two usages for this method:


  • On lists of values, it simply computes an operation on the values (+, min, max)

  • On list of objects, it will compute an operation on results of expressions on the object.

Example

Example: List.1 ->Compute("+","","",Length.1)

This example sums all the values of the list.

Where:


  • List.1 is the name of the list on which the calculation will be performed
  • + is the operator used. (Supported operators are: +, min, and max.)
  • The first string must be empty to indicate that we work on list of values.
  • The second String must also be empty when working on list of values.
  • Length.1 is the output parameter.

Example:

List.1 -> Compute("+","Hole","x.Diameter+x.Depth",Length.1) This example sums all the addition of the diameter and the depth of all holes in the list. Where:


  • List.1 is the name of the list on which the calculation will be performed.
  • + is the operator used. (Supported operators are: +, min, and max.)
  • The first string contains the expected type of the objects of the list (in this case, it is a list of holes).
  • The second String contains a formula that will be computed on each element of the list (holes in this case) and that will return a value. In this expression the variable x is used to represent the element in the list. One can then access its attributes for instance.

Length.1 is the output parameter.

List -> Apply (Type:String, Expression: String): VoidType

Applies a given expression to the objects of a list that are of a given type.In this expression, the element of the list is represented by a variable named x.

Example

//Finds all rule bases and executes them let L (List) //P being Part Feature /* Finding a value */ L = P -> Query("Rulebase","") L -> Apply ("RuleBase","x -> Update()")

List -> Filter(Type:String, Condition: String): List

Method used to filter a list of objects by extracting the objects that fulfill a Boolean expression. This method has the following signature: List.Filter(String TypeName,String Expression) : List

Arguments


  • TypeName is the type of the objects that the user wants to extract (it can be "". In this case, no filtering is done on types).

  • The second string Expression corresponds to the Boolean expression that must fulfill the objects of this given type. In this expression "x" is used as the variable name of type TypeName. This string can be equal to "". In this case, no expression is checked.

Example

I = (List -> Filter("Hole","x.Diameter > 3mm")).Size() I = (List -> Filter("Hole","")).Size()
I = (List -> Filter("VPMReference","x.V_maturity == \"IN_WORK\" ")).Size()

+(List1: List, List2: List): List

Operator enabling you to add two lists and to return a third one. Adding two lists means concatenating the elements of the two lists and affecting the result to the returned list. The elements of the first list will be at the beginning of the resulting list. The order of the elements is kept.

This operator works on list of objects (persistent or not) or on list of values (persistent or not).

If the operation required is not feasible (for example, trying to fill a persistent list with a non persistent value), evaluation errors are raised.

There is no simplification of the list (an element can be there twice after the operation).

Example

Let L1(List) Let L2(List) Let L3(List) L3=L2+L1

List -> Extract(Type: String, TypeOutput: String, Expression: String):List

Method used to extract the items of a given type.

Arguments


  • Type: Knowledge types considered by the extract function meaning that the list is first filtered to take only elements of a given type into account. The type can be a value type or an object type.

  • TypeOutput: Type of the object produced by the Extract method. The output list contains the objects of this given type. The type can be a value type or an object type.

  • Expression: Knowledge rule expression with two arguments, x of type Type and y of type TypeOutput. The expression must valuates y depending on the expression computed on x. The expression can use the if, else, for, let keywords like in a rule.

Note that:


  • The list in output contains elements computed by the expression on all the objects filtered on the list. The list may be empty and its size may be less that the list in input if some elements of the list in input have been filtered because they were not of the right type.

  • If Type or TypeOutput are not a recognized type, an evaluation error will be raised.

  • If the Expression is not syntactically correct, an evaluation error is raised.

Example

Let L1(List) Let L2(List) ... L2=L1 -> Extract("Hole","LENGTH","y=x.Diameter+x.Depth")

In this example, we produce a list in output that is the extraction of the sum of the diameter and the depth of the holes in the list.

List -> Sort (Operator: String, Type:String, TypeOutput:String, Expression: String):List

Method used to sort lists. It operates the sort based on a criteria that corresponds to an extraction (see previous method).

Arguments


  • Operator: Accepted values are "<", ">". These operators are used to sort the list.

  • Type: Type of the list objects taken into account. It can be a type of value or a type of object. The type must be indicated because it is used to validate the expression. All objects of the list should be inheriting from this type.

  • TypeOutput: Type of the object produced using the sort method. The output list contains objects of this given type. The type can only be a value type. It can be a Real or a String.

  • Expression: Knowledge rule expression with two arguments, x of type Type and y of type TypeOutput. The expression must valuate y depending on the expression computed on x. The expression can the if, else, for, let keywords like in a rule.The expression can be empty if the list is a list of values.

Note that:


  • If the operator is not equal to ">" or "<", an evaluation error is raised.

  • If Type or TypeOutput is not a recognized type, an evaluation error is raised.

  • This method does not operate on the list itself but produces the sorted list in output. As a consequence, to solve the problem, we should have created a new List and valuated it with: NewList = FilletRadius > Sort(>,LENGTH,LENGTH,)

This example sorts a list of values.

NewList = HoleList -> Sort(">","LENGTH","LENGTH","y=x.Diameter") This example sorts a list of holes based on their diameter.

List -> RemoveDuplicates

Method used to modify the content of the list by extracting the duplicated elements.

When the list references objects (features and parameters), it removes the duplicated reference to the objects. When the list references volatile values, it removes the equivalent values.

Note that this method does not have the same behavior on lists of parameters and on lists of values. On Lists of parameters, it removes the parameter that are present twice in the list. On lists of values, it removes the values that have the same value.