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 HyperWorks Desktop 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 entity panels 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:
- 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" 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.k.value" access the mass of the body and the radius of gyration.
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})`
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):
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:
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.