Controlling FlexSim Externally


Once you have a FlexSim model built and properly configured, you may want to utilize that model in a more automated way. You may want to make the model into a fully operational digital twin, that either provides live decision support to your management team, or actually makes decisions in your automated factory. Alternately, you may want to simply create a script that you can manually run to perform some batch analysis tasks. FlexSim provides several solutions for controlling FlexSim externally.

Using the Command-Line

You can launch FlexSim from a Command Prompt or a batch file, and open a specific model by executing a line like this:

"C:\Program Files\FlexSim 2022\program\flexsim.exe" "C:\Users\username\Documents\Flexsim 2022 Projects\test.fsm" /maintenance nogui_disablemsg

This will open FlexSim, open the model at the specified path, set a flag to suppress showing FlexSim's interface, and set a flag to suppress any msg() command popups from appearing.

The 'maintenance' features are optional. For instance, remove the nogui flag to launch FlexSim with the normal interface.

Running FlexScript from a File

You can also execute FlexScript that is stored in a file when you open your FlexSim model:

"C:\Program Files\FlexSim 2022\program\flexsim.exe" "C:\Users\username\Documents\Flexsim 2022 Projects\test.fsm" /maintenance nogui_disablemsg_runscript /scriptpath C:\myscript.txt

This will run the FlexScript code stored in the file C:\myscript.txt when the model opens.

This allows you to run a script, stored in a separate file, that can be separately and independently edited without modifying anything inside the model file.

Running FlexScript in the Model

Another option for running scripts in the model is to put some script into your OnModelOpen trigger. You can use the commandlineparam() command to get a command line parameter. In this scenario, the command line command would be something like:

"C:\Program Files\FlexSim 2022\program\flexsim.exe" "C:\Users\username\Documents\Flexsim 2022 Projects\test.fsm" /maintenance nogui_disablemsg /automated true

Then, in your OnModelOpen trigger:

if (commandlineparam("automated") == "true") {

You can then use other triggers in your model, such as a Sink's entry trigger, to write to an output file (fileopen(), fpt(), fpr(), fpf(), fileclose(), etc.), write to a database (Database.Connection API), etc., and then exit FlexSim (cmdexit()).

Using Python

You can also control FlexSim using python. FlexSim has created a GitHub project called FlexSimPy. In addition to providing source code to customize FlexSim's mechanism for connecting to python, this repository includes a DLL project that builds a python module, with an interface for controlling FlexSim. The repository is at As of 2022, you still need to build this python module yourself, although we hope to soon provide pre-compiled packages that you can install using pip. Please refer to that repository's wiki page for more information.