question

Jackie Ho avatar image
8 Likes"
Jackie Ho asked Phil BoBo commented

Automatically Configure and Run a FlexSim Model

If I have a model that is built and ready, is it possible for FlexSim to import various object and model parameters automatically? And run the simulation automatically?

excelimportcommand lineauto runonmodelopen
5 |100000

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

Jeff Nordgren avatar image
4 Likes"
Jeff Nordgren answered Ben Wilson edited

A FlexSim model has an On Model Open trigger. Here you could put whatever logic you like, including importing data from Excel or a database, setting the runspeed, and starting the model run. This screenshot shows how to add an On Model Open trigger to your model:

If you want the model to open automatically when FlexSim starts, you can launch FlexSim and open the model at the same time by double-clicking the model file.


5 |100000

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

Ben Wilson avatar image
22 Likes"
Ben Wilson answered Phil BoBo commented

Command line options

Alternatively, you can launch FlexSim from a Command Prompt or a batch file, by executing a line like this (this text probably wraps in this web view, but in the command prompt it should all go on a single line):

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

This will open FlexSim, open the model at the specified path, set a flag to suppress showing FlexSim's interface, set a flag to suppress any msg() command popups from appearing, and execute the file C:\myscript.txt as FlexScript.

All of those command line features are optional. For instance, remove the nogui flag to launch FlexSim with the normal interface. You can put FlexScript code into myscript.txt to run custom behaviors in the model, such as resetting and running the model, but that is optional. Remove the runscript flag, plus the "/scriptpath C:\myscript.txt" portion from the line if you don't wish to run a FlexScript file on model load.

Using an external script file that runs upon opening the model is an alternative to having the OnModelOpen trigger coded into your model. Instead you can have an external script file that can run upon model open, that can be separately and independently edited without modifying anything inside the model file.

Attached is a zip file containing 3 files that show an example of how you can silently run a FlexSim model without an interface and then export results to a text file.

Extract these 3 files to your computer somewhere (I put them on my Desktop).

Edit runScriptDemo.bat so that it has correct paths to where you have installed FlexSim, where the model is, and where the script file is.

  1. "C:\Program Files\FlexSim 2016\program\flexsim.exe" "C:\Users\username\Desktop\test.fsm" /maintenance nogui_disablemsg_runscript /scriptpath "C:\Users\username\Desktop\script.txt"

The script file (script.txt) has code to run the model:

  1. resetmodel();
  2. runspeed(10000);
  3. go();

The Sink's OnEntry trigger in the test.fsm model has code that exports results as a file and closes FlexSim.

  1. cmdexit();

· 18
5 |100000

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