Use the Expression Builder

The expression builder allows you to enter expressions in text boxes without extensive typing and memorization. It can be used to construct mathematical expressions that are a function of the model parameters.

There are two types of expressions that MotionView can create:

  • Parametric expressions
  • Solver functions

MotionView evaluates both parametric expressions and solver functions through a text and numeric parser known as Templex.

Parametric Expressions

These expressions are created to relate one of the values of a modeling entity to another entity within the model. The data type of the value returned by the parametric expression should match the data type in the field of the entity the parametric expression defines. For example, if the parametric expression is defining the location of a MotionView point, then a real number needs to be returned by the parametric expression. When incorrect data types are returned by the parametric expression, an "Error Evaluating" message will appear in the data entry field. These entry fields are found on the Entity Editor for points, bodies, bushings, spring dampers, forces, and other MotionView modeling entities.

The parametric expression can also use the mathematical operators and functions available in the Templex text and numeric language.

Example 1

Consider two points in a model with variable name "p_1" and "p_2". To parametrically place the X location of "p_2" +10 units away from the X location of "p_1", a Templex parametric expression can be used. The parametric value of the "x" coordinate for "p_1" is the data member "x" and is accessed using the expression "p_1.x". Therefore, to place the point "p_2" +10 units from the X location of point one, the expression "p_1.x +10" is entered in the X coordinate field of "p_2", as shown in the figure below:

Figure 1. Panel


Figure 2. Entity Editor
Figure 3. modeling window
Example 2

In the example below, the expression builder is used to parameterize the moment of inertia about the x-axis of a body. In this parametric expression, the mass of the body with the variable name "b_body" is multiplied by the squared data set variable "k" (defined in a dataset "ds_param") representing the radius of gyration. Please notice, to access the real values for the mass and radius of gyration, the variable name is followed by a "." and the data member's name. In the example below, the statements "b_body.mass" and "ds_param.k.value" access the mass of the body and the radius of gyration respectively.

Figure 4.


Solver Functions

This type of expression contains a combination of unevaluated strings and evaluated parametric expressions. Solver expressions are used to build functions that are created in the solver input deck when MotionView exports the model. These expressions define values for MBD entities such as bushings, spring dampers, force vectors, and motions. Solver functions are the input type when any "field type" in the MotionView entities property tab is set to Expression. The following list defines how entities are evaluated in solver functions:
  • The entire solver function is enclosed within back quotes (` ` ).
  • Parametric expressions within the solver function are enclosed within curly brackets ({}). When MotionView encounters solver functions enclosed in back quotes, any parametric expressions enclosed in the curly brackets are evaluated by the Templex parser as the model is exported to the solver input file (.xml file for MotionSolve). In other words, the evaluated parametric expression is written to the solver input file rather than the Templex operators, functions, and variable names enclosed in the curly brackets.
  • Parts of the expression not enclosed in curly brackets are directly written to the solver input file – no evaluation occurs.
  • If back quotes do not enclose the solver function, MotionView will evaluate the entire expression with the Templex parser, which probably will result in an error.
Example

To ramp a force from zero at 1-s to 500 times the distance between two markers at 1.5-s using the MotionSolve STEP function, the following expression is created in MotionView:

`STEP(TIME,1,0,1.5, 500*DX({m_1.idstring},{m_2.idstring}))`
Figure 5.


According to the rules for evaluating the solver function expression, MotionView evaluates the Templex values within the curly brackets, ignoring all other text in the function. In this particular case, the MotionView parametric variables "m_1.idstring" and "m_2.idstring" evaluate to the IDs, in string format, of the marker entities with variable names "m_1" and "m_2". Therefore, when the MotionSolve input deck is created by MotionView, the expression in the figure below is created in the .xml file (assuming the marker IDs of m_1 and m_2 are 30102010 and 30102011 respectively):

Figure 6.


To ensure the parametric arguments to the solver function are correct, you can evaluate the solver expression by selecting the Evaluated check box, as shown in the figure below:

Figure 7.


Note: The IDs of markers and other MotionSolve entities are not defined before the model is exported to a solver or the MotionView operation “Check Model” is performed. Therefore, the marker IDs in the expression builder may appear blank when the parametric expressions are evaluated in the expression builder dialog box.

The Evaluated check box only applies the Templex parser to the solver function (the parametric value and expression in the curly brackets). The correct format of the other information in the expression is solver dependent and is not checked by MotionView. For example, if the step function was written “stp”, MotionView would not produce an error message when Evaluated is checked. However, MotionSolve would create an error at run time.

Create Expressions

  1. Access the expression builder by opening a panel, clicking in a text field, and selecting from the trio of buttons at the top of the panel .
    Figure 8.
  2. The text box at the top of the expression builder contains the expression that you are editing. Insert the cursor anywhere in the box and type directly into the field or use the number pad and list of commonly used functions at the bottom of the dialog to build your expression.
    Tip:
    • Click the Font button to display the Font dialog, which allows you to select font types, font styles, and font sizes for the expression.
    • Select the Evaluated check box to evaluate the expression.
  3. Use the tabs in the middle of the dialog to access additional property names and solver functions.
    TabDescription
    Properties The Properties tab is used to insert entity names and property names into an expression. When you highlight an entity or a property in the list, the variable name of that property is displayed directly above the list. Click the Add button to insert the property name into the expression in the text box.
    Tip: Clicking the Filter entities within valid scope option assists you in picking entities within the same system, assembly, or analysis by filtering the relevant options.
    Motion The Motion tab contains MotionSolve and ADAMS functions associated with displacements, velocities, and accelerations. When you press a function button, the function is inserted into the expression at the current cursor location.
    Force The Force tab contains MotionSolve and ADAMS functions that will provide the forces and moment measures for either:
    • modeling entities that have a force associated with them (for example, forces, flexible connectors, joints, and motions)
    • the sum of all the forces/torques between two markers
    General The General tab contains miscellaneous MotionSolve or ADAMS functions.
    Location The Location tab contains MotionSolve location functions that can be used to find a position in the global frame, given the position in a different coordinate frame or another entity that has a position attribute (such as point or marker).
  4. Click OK.
    The new expression is displayed in the text box in the panel.
Tip: To learn more about using the various functions, see the MotionSolve Functions topic.