MotionView User's Guide

Expression Builder

Expression Builder

Previous topic Next topic No expanding text in this topic  

Expression Builder

Previous topic Next topic JavaScript is required for expanding text JavaScript is required for the print function  

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.  To access the Expression Builder, click in a text field and select the F(x) button, fx_button, from the trio of buttons at the top of the panel, expr_bldr_icons.

fxdialog2

Expression Builder

The expression builder contains three sections:

Top section

The text box at the top of the expression builder contains the expression that you are editing.  You can type directly into this field by inserting the cursor anywhere in the box.  You can use the mouse to highlight sections to cut, copy, paste or delete.  If your expression is wider than the text box, it wraps to the lines below.  For large expressions, click the vertical scroll bar at the right of the text box to scroll through the text.

 

Font

Click the Font button to display the Font dialog. The Font dialog allows you to select font types, font styles, and font sizes for the expression.

 

Apply

Click Apply to apply the changes made to the expression.

 

Undo

Discards any changes that were made since the last time the Apply button was clicked.

 

Evaluated

Activate this check box to evaluate the expression.

Middle section

Four tabs hold property names and solver functions that you can insert into an expression.

Properties

Motion

Force

General

Location

Bottom section

A number pad and a short list of the most commonly used functions.

OK

Click OK to apply the changes and exit the Expression Builder dialog.

Close

Click Close to exit the dialog.

Creating Expressions

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, SpringDampers, 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” & “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:

expr_bldr_point_example_mv

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 members 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 values.

expr_bldr_point_example2_mv

Solver Functions

This type of expression contains a combination of unevaluated strings and evaluated parametric expression.  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”, “Curve”, or “Spline3D”.  Please note, in the “Curve” or “Spline3D” the solver expression is defined in the “Independent Variable”.

The 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})`

expr_bldr_solver_func_example_mv

According to the rules for evaluating the solver function expression, MotionView evaluates the Templex values within the curly brackets ignoring all the other text in the function.  In this particular case, the MotoinView parametric variables “m_1.idstring” and “m_2.idstring” evaluate to the IDs, in string format, of the marker entities with a 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):

expr_bldr_step_example_mv

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:

expr_bldr_evaluated_option_mv

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

 

See Also:

MDL Variables - SolverCR and SolverDtoR

Templex Reference