question

Mike Mayer avatar image
3 Likes"
Mike Mayer asked Brandon Peterson edited

How to get name of global table most recently populated by MTEI?

I am able to import Excel sheets into global tables no problem.

I would like to then use "Post Import Code" to scan the newly populated global table for numeric strings that contain a percent sign.

If a percent sign is in an Excel cell as a result of being pasted (like, someone pasting 3.141% into Excel), MTEI will import it as a flush-left string "3.141%" versus it being a fractional value 0.03141 (which would then have correctly shown up up in the global table as a true number, flush right).

Interestingly, if the data in the Excel cell is originally 0.3141 and AFTERWARDS you do a Format Cells in Excel to display it in the Excel cell as a percent 3.141%, then FlexSim still brings it in correctly as 0.3141.

This difference in how the original Excel cell's data was created (pasted, versus Format Cell), has tripped us up numerous times. So, we thought we'd just do some simple data cleansing on the FlexSim side by scanning a just-imported global table for 1) a percent sign character "%" suffix on any string in a global table cell, then 2) determine if everything to its left is either a numeral, with or without the decimal point. In which case, we can assume with some confidence that it's actually a percentage value (like 3.141%) even though represented as a string inside the FlexSim global table.

When these percent values are discovered, we can then (I think) do some simple string-to-number conversion in FlexScript (in the Post Import Code) and re-write the fractional percent value back into the same global table cell as truly numeric 0.03141, i.e., the true fractional percent value.

The other solution of course, is to ban our own use of percent signs in the source Excel sheet. However, there's no guarantee that someone might do it anyway in the source Excel sheet (because in this application, the input Excel sheets for MTEI are created by humans). Thus, some light data cleansing is in order - we just need the name of the table that was just populated by the MTEI so we can scan it for percent symbols. I searched the Forum and the FlexSim manual, but didn't see a way the table's nodename is getting passed to the OnImport code. Note that we will likely only import one table at a time (Post Import Code I believe is executed after 1 or more tables is loaded).

Thanks, Mike - Goodyear

FlexSim 7.7.4
excelpost import code
5 |100000

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

1 Answer

Brandon Peterson avatar image
4 Likes"
Brandon Peterson answered Ben Wilson edited

Mike,

The Post Import Code is only executed once at the end and there are no references to the tables that were updated passed into the function.

This means that you will have to look through all of the possible tables each time the import is executed. Here is some sample code that you can put into the Post Import Code that will loop through the tables that the data is placed into if you don't want to manually code the reference to each one in the Post Import Code:

  1. #define EXCEL_TABLE_LOCATION_RANK 3
  2. #define EXCEL_TABLE_NAME_RANK4
  3. table = getvarnode(ownerobject(c), "importtable");
  4. for(int i1 = 1; i1 <= gettablerows(table); i1++){
  5. treenode row = rank(table, i1);
  6. string tablelocation = gets(rank(row, EXCEL_TABLE_LOCATION_RANK));
  7. string tablename = gets(rank(row, EXCEL_TABLE_NAME_RANK));
  8. treenode tableNode = node(concat(tablelocation, strlen(apchar(tablename))>0?"/":"", tablename), model());
  9.  
  10. /*Insert your code to evaluate your table here*/
  11. }

Good Luck,

Brandon

· 4
5 |100000

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