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.

Methods Available in All 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).
  • 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 (object not of the expected type)
    • avoid uncertainties. For example, if you write length(List.GetItem(i)), the system can choose the length function on curves or the length function 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 L2(List)
    Let L3(List)
    L3=L2+L1
  • List >  IndexOf (Element: ObjectType, StartIndex:Integer):Integer
    Returns the first index of a list item. The item is searched for from the start index.

The function described below are available in the Action editor only
  • Copy (List: List) : List
    Method used to copy the content of a list and paste it in another list.
     
  • List (Next: ObjectType, ...): List
    Method used to create a list.
    List(Item1, Item2, Item3)
     

Methods Available in the Action and the Reaction Editors Only

  • 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
  • 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.
  • List > RemoveItem (Index: Integer) :VoidType
    Method used to remove an item from the list.
     
  • 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.
     
  • List > Compute(Operation: String, Type: String, Expression: String, Result: out UndefinedType): VoidType
    Function used to compute the result of an operation performed on the attributes supported by the features contained in the list. It is available for Actions, Reactions and in Knowledge Expert.
    Example: List.1 .Compute("+","","",Length.1) 

    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 "" is the type of the list items used for the calculation (to calculate the diameter, the type to be indicated is Hole, to calculate the volume, the type to be indicated is Solid)
    • The second"" stands for the list items. Note that the type of the items contained in the list must be identical.
    • 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.

Example:

//Finds all rule bases and executes them
Expression1 (P: #In PartFeature)
{

 /* Finding a value */
let L (List) 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 (in 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()
 

  • +(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).
 

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

Method used to extract some information on the items of the list.

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 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.
     
  • List    >    Sort (Operator: String, Type:String, TypeOutput:String, Expression: String):List

Method used to sort lists.

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 Extract 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.
     

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","")

     
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