0 Votes

References to objects in script

Last modified by WikiBot on 2025/03/20 14:15

References to data objects and attributes

References to data objects in scripts are enclosed in square brackets:

 
[@ step1 ... stepn] reference to object;
[step1 ... stepn] reference to value (but same as [@ step1 ... stepn] if it not a parameter or a variable);
[step1 ... stepn attribute] reference to an attribute of [@ step1 ... stepn]
(step1 ... ) may denote a path to an object. It is not evaluated (but every step is evaluated). A path may be passed to a function that may treat is as a reference and evaluate it.


The references are always relative to the base object. Every step describes the transition to the next object or value in the path.

A step may be

  • A component name (symbol or string) or an attribute name (always symbol, see Options and attributes for list of attributes);
  • A keyword (a symbol starting with :) or an expression #'name denoting a function to be applied to the previous object;
  • A data object (or element of an array object) denoting the target of transition (the previous object is ignored);
  • An integer denoting an index in an array object or in a list of objects;
  • Symbol * denoting a slice of an array;
  • An expression evaluated (with previous object as the base) to the target object. Note that the steps in a reference are already evaluated (with the script’s base). To prevent double evaluation either write it as 'step or (QUOTE step);
  • If the previous object is a resource parameter (or its component with name model is a resource parameter) and the step cannot be applied to the previous object, it is applied to the referenced resource;
  • If the previous object is an interface, the step may denote the name of the interface member (as defined in the interface type). For interfaces with single variable the step may also denote an attribute of that variable. The step :new extends an array interface and returns the new element.


A “data object” may be here

  • An instance of a data object or an element of an array object (object index ...);
  • A list of data objects. In this case
    • the “component” step either returns the named member of the list or (if there is no such member) is applied to every member and returns the list of results;
    • the “index” step treated as position in the list (starting with 1);
    • the “data” step returns that data;
    • all other types of steps are applied to every member of the list and return the list of results.
  • A vector (not string). In this case
    • the “index” step treated as position in the vector (starting with 0);
    • the “data” step returns that data;
    • all other types of steps are applied to every element of the vector and return the vector of results.
  • Any other value supports only “data” steps. Particularly, if the base object is NIL, any reference should start with a data object.


When a path is passed to a function, the interpretation of the path may be slightly different from the described procedure (we are trying to eliminate such differences).


Here is a list of useful keyword functions that may be used as steps in references (more functions are defined in applications):

 
:parent The parent object (containing this one as a component)
:model The minimal NMF/Modelica model or a boundary object or an output object or a macro object containing this one as a (sub)component
:macro The minimal macro object containing this one as a (sub)component
:system The system containing this object
:simres For an output object (or a component of such object) returns the collection of results containing this object (introduced in IDA 4.7 for storing results of multiple simulations)
:root The maximal data object (system or project) containing this object
:lib The current IDA application
:sys The object containing common definitions for all applications
:self Returns the argument itself
:ref For resource parameters: the referenced resource
:name The object name translated to the current language
:full-name The qualified name (relative to the system) in the current language
:global-name The qualified name (including the system name) in the current language
:value For parameters and variables: The value translated to the current language
:actual-value Same as :value, but if the value is :default returns the actual default value
:unit Returns the measurement unit translated to the current language.
For models returns the model type.
:total If the value of the object is a list, the function returns the sum of all members.
:description Translated object description or the name if no description
:description1 Translated object description
:type Returns the object type (maybe user-defined) translated to current language
:given For a variable, returns text describing the binding of variable (as presented in the field “given”)
:parameters
:variables
:interfaces
:resources
:components
:boundaries
:results
:versions 
Returns the list of components of these type. More component categories may be defined in applications.
:all-variables
:all-parameters 
Returns the list of components of these type of this object and all its (sub)components
:all-resources Returns a sorted list of all resources available in the object
:all-results Returns the list or result objects in the given collection of results (or results of the last simulation when the function is applied to a macro object) and in their (sub)components
:origin Returns the object at physical level corresponding to the given mathematical model
:logged-to Returns the output file there the given variable is logged to (or NIL if not logged)
:array-elements Returns list of all elements of an array object
:error Interrupts the evaluating of the reference; the reference is treated as invalid