question

Erik RV2 avatar image
0 Likes"
Erik RV2 asked Ben Wilson commented

Import From Excel When Model is ran programmatically

As somebody tried to import from excel while launching the model from a shell?

I run a FlexSim model programmatically with this post’s configuration:

https://answers.flexsim.com/questions/21116/automatically-configure-and-run-a-flexsim-model.html

To the files shared in this post, I tried adding this line:
excelmultitableimport();

to
'onModelReset' trigger and/or
'script.txt'

without constant success.

I tried with FlexSim 20.1 and 20.0 and I am opened to go from one version to another.

Thanks for your support!

FlexSim 20.1.0
flexsim 20.1.0excel importole automationshell
· 2
5 |100000

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

Jordan Johnson avatar image Jordan Johnson ♦♦ commented ·

Are you launching multiple instances of FlexSim from the shell? The way we import from Excel is limited to only one "reader" at a time. If multiple instances of FlexSim all try to read from a single workbook, then the data will not import correctly.

If not, then it should work, but you'll need to post a model so we can help you get your model working, or discover the exact bug.

0 Likes 0 ·
Erik RV2 avatar image Erik RV2 commented ·

@jordan.johnson,

There is only one instance of Flexsim ran at a time.

Attached you will find files representing a sample of the workflow I want to build:

  1. 'User_Interface.xlsm' Allows:
    1. Generating the ‘inputs.xlsx’ tables
    2. Running the model programmatically (with the 'scriptToRunModel.txt' file)
    3. Retrieving the output logs
  2. ‘inputs.xlsx’ contains two tables to systematically import in ‘model.fsm’ (excelmultitableimport(); is set 'onModelReset')
    1. A global table containing an integer (aInt_toGlobalTable)
    2. A ProcessFlow arrival schedule
  3. ‘onRunStop’ two logs are generated:
    1. ‘outputGlobalTable.csv’; will log aInt_toGlobalTable+1
    2. ‘outputSchedule.csv’; contains the count of tokens in the ProcessFlow arrival schedule

With this sample:

  1. The 'excelmultitableimport();' doesn't work when model is ran programmatically
  2. When the model is ran through the Flexsim API, the tables are not always importing (sometime it requires resetting twice the model)
  3. I also tried inserting 'excelmultitableimport();' in the first line of 'scriptToRunModel.txt' and it hasn't proven constant success neither

Thanks for your help!

Import Table programmatically.zip

0 Likes 0 ·

1 Answer

Jordan Johnson avatar image
0 Likes"
Jordan Johnson answered Ben Wilson commented

I'm having trouble using the Excel Import tool in batch mode. It may not be designed for that case. I'll put it on the dev list, and if it's a bug, we'll fix it.

In your shoes, I would look at using importtable() with .csv files.

· 1
5 |100000

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

Erik RV2 avatar image Erik RV2 commented ·

Hi Jordan.

I tried using importtable() with .csv files. from the Flexsim API and it works great for global tables, but I had trouble with the Processflow arrivals schedule tables.

See example code below:

//Working: Global table from csv
importtable(Table("testScheduleTable"), "inputSchedule_withHeader.csv", 1, 0);

//Not working: Processflow arrivals import from csv
treenode source = getvarnode(model().find("Tools/ProcessFlow/ProcessFlow/SourceSchedule"), "arrivals");

//try1. doesn't import to the processflow arrivals - all schedule is set to 'null'
importtable(source.as(Table), "inputSchedule_withHeader.csv", 1, 0);

//try2. imports - header is used as an arrival value
importtable(source.as(Table), "inputSchedule_withHeader.csv", 0, 0);

//try3. imports arrival values - but erases headers
importtable(source.as(Table), "inputSchedule_withoutHeader.csv", 0, 0);

Do you have example code doing something similar without erasing the headers?

Thanks!

0 Likes 0 ·