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?
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?
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.
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):
"C:\Program Files\FlexSim 2016\program\flexsim.exe" "C:\Users\username\Documents\Flexsim 16 Projects\test.fsm" /maintenance 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.
"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:
resetmodel(); runspeed(10000); go();
The Sink's OnEntry trigger in the test.fsm model has code that exports results as a file and closes FlexSim.
cmdexit();
Hi, Ben.
I'm looking for a way to run some automation as well and I was wondering if it is possible to control FlexSim using MS PowerShell, a much newer solution, instead of CMD Prompt, an old and far more limited solution.
I do know it is possible to call the CMD from PowerShell and use the solution above, but it's not a good solution. A more elegant one would be calling FlexSim directly from PowerShell.
I couldn't find any information here at the forum or in the FlexSim user manual.
I would appreciate any suggestions.
Thanks!
Use the Start-Process cmdlet.
Start-Process -FilePath "C:\Program Files\FlexSim 2018\program\flexsim.exe" -ArgumentList "C:\Users\phil.bobo\Desktop\test.fsm /maintenance runscript /scriptpath C:\Users\phil.bobo\Desktop\script.txt"
Hi @phil.bobo,
do you know if there is a trouble when the script is saved in a folder which name contains a space?
I executed your code in two different ways and I obtained two different results.
First test works without space and results is good.
Start-Process -FilePath "C:\Program Files\FlexSim 2018\program\flexsim.exe" "/maintenance runscript /scriptpath C:\Users\amerl\Desktop\Folder_Without_Space\FlexScript.txt"
Second test works with space and the script isn't executed.
Start-Process -FilePath "C:\Program Files\FlexSim 2018\program\flexsim.exe" "/maintenance runscript /scriptpath C:\Users\amerl\Desktop\folder with space\FlexScript.txt"
The file FlexScript.txt simply contains this code
msg("Hello","World",1);
Any idea?
Thanks for the support!
Hi,Ben
I use your way to launch Flexsim
But it will take a long time to run in my model(almost 20 mins)
Although my model is more complicated, I don’t think it takes so long.
my computer have i7 8th CPU,32G Ram,so it shouldn't be the reason for my computer.
Loading a model from the command line and starting the simulation via code doesn't automatically make the runspeed go at its maximum, the way background simulations do when using the experimenter or optimizer.
Instead, you need to use a script to set the runspeed to some high value, like:
runspeed(99999999);
Or something similar.
You can also confirm a typical run duration for your model by running it normally in FlexSim at max speed. If it can finish in 4-5 minutes through the regular interface, it should finish in 4-5 minutes when started from the command line.
Hi everyone!
As somebody tried to import from excel while launching the model from a shell?
To the files shared in this post, I tried adding this line:
excelmultitableimport();
to
'onModelReset' trigger and/or
'script.txt'
without constant success.
Thanks!
Another command line parameter:
You can pass the command line parameter /excludemodules modulename1,modulename2,etc to exclude specific modules.
Ben,
How did you tell FlexSim to save the output into the "results.txt" file?
The Sink's OnEntry trigger has code that writes the results.txt file using FlexScript commands:
10 People are following this question.
FlexSim can help you understand and improve any system or process. Transform your existing data into accurate predictions.
FlexSim is a fully 3D simulation software environment. FlexSim can be used to simulate any process in any industry.
FlexSim®, FlexSim Healthcare™, Problem Solved.®, the FlexSim logo, the FlexSim X-mark, and the FlexSim Healthcare logo with stylized Caduceus mark are trademarks of FlexSim Software Products, Inc. All rights reserved.
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © Autodesk Inc. All rights reserved