Using DynamicSelect in Icons

DynamicSelect is a feature which allows the user to dynamically change aspects of the model during simulation.

The function syntax is as follows:

name of graphical feature = DynamicSelect (editing state, dynamic state)


Where any graphical feature, such as coordinates, colour, text, etc., in graphical annotations can be dependent on class variables using the DynamicSelect expression. DynamicSelect uses the same syntax of a function call with two arguments:

  1. The first argument specifies the value of the editing state and the second argument the value of the non-editing state. The first argument must be a literal expression.
  2. The second argument may contain references to variables to enable a dynamic state or behaviour.

An example from the Modelica.Fluid library: The level of a tank could be animated by a filled rectangle drawn in the icon layer. The height of the rectangle would expand in vertical direction depending on how full or empty the tank is. Its colour could also be dynamic and depend on a variable linked to tank overflow. The icon layer section of the tank annotation looks like this:

annotation (Icon(graphics={Rectangle(extent=DynamicSelect({{0,0},{20,20}},{{0,0},{20,level}}), 
fillColor=DynamicSelect({0,0,255}, if overflow then {255,0,0} else {0,0,255}))});


Figure 1. Tank fill extent dependant on fluid level_NV

Figure 1. Tank fill extent dependant on fluid level.

The same philosophy can be applied to other drawing objects such as arrows and also colour of the fill and objects:

Fill colour change:

fillColor=DynamicSelect({170,213,255}, colorVector),


where colorVector is a vector of size 3 setting the {R,G,B} values for the fill colour (Red, Green, Blue):

Figure 2. Pipe fill colour dependant on fluid temperature

Figure 2. Pipe fill colour dependant on fluid temperature.

Changing the polygon shape:

points=DynamicSelect({{-20,15},{20,0},{-20,-15},{-20,15}}, pointsVector),


where pointsVector defines a set of point coordinates which changes the shape, position or geometrical flattening of the arrowheads:

Figure 3. Arrow direction dependant on fluid flow direction

Figure 3. Arrow direction dependant on fluid flow direction.

Written By: Alessandro Picarelli & Garron Fish


Got a question? Just fill in this form and send it to us and we'll get back to you shortly.


© Copyright 2010-2024 Claytex Services Ltd All Rights Reserved

Log in with your credentials

Forgot your details?