Paul Toone avatar image
Paul Toone posted Brandon Peterson edited

User Commands Concepts   

User Commands are accessed from the Toolbox. (View menu > Toolbox > Add > Modeling Logic > User Command).

The User Commands tool lets you add, delete, and edit custom commands in your model.

Once you have created your command you can call it like any other FlexSim command. It will appear in blue when typing code and it will appear in the Command Summary. You can also hover the mouse over the command and press F1 to display the Command Helper.

Note on calling user commands from C++: When calling a user command from C++, all parameters passed will need to be converted to a number, or else you may get compiler errors. To convert a parameter to a number, use the tonum() command.


The following are some of the valid parameters you can enter in the Parameters and Return Type fields:

treenode  node  obj  string  str  num  int  double  treenodearray  intarray  doublearray  stringarray  var

The var parameter with accept any of the datatypes. To specify multiple datatypes but not include all datatypes you can concatenate parameters together using a forward slash:


In the Parameters field you can have optional parameters by enclosing the additional parameters in square brackets at the end of the list:

(var object, num type [, int flags])

Accessing Parameters

If your command specifies any of the above data types as parameters that will be passed in to the command, you can access those parameters through the param command:


Where num is the rank from the parameter list. For example, if the parameters was specified as:

(treenode dataNode, num maxNumDataPoints, num incrementValue)

You would access those values in your code by:

treenode dataNode = param(1);  double maxNumDataPoints = param(2);  int incrementValue = param(3);

Note on Parameters and Return Type: The values specified here will be used by the FlexScript parser. The number of parameters and their datatypes will give FlexScript warnings if not passed in as documented in the Parameters section here. If the return type is incorrecly used in code, it will return a FlexScript error and not build correctly. You can specify the parameters list as (...) and leave the return type blank for the FlexScript parser to ignore them. For examples of parameter lists and return types, view the Command Documentation.


When you open the command documentation from the menu Help > Commands, the user commands will be shown in the command documentation in addition to all of the built-in FlexScript commands. The description field shown above will be displayed as html so you can use html markup for formatting, such as <b> and </b> for bold. Because the description allows for html markup, some standard characters do not work properly, such as <, >, &, and new line characters. To display these types of characters, you can use special markup codes, such as "&gt;" (without the quotes) for a > symbol and <br/> for a line break. If any of the commands' descriptions container invalid html markup, FlexSim may throw an exception when you try to open the Users Manual and your commands will not be properly documented.

flexsim users manualusers manualuser command
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.



brandon.peterson contributed to this article paul.t contributed to this article


FlexSim 2016.1