Evaluating FlexScript cells in Global Table after MTEI import

Evaluating FlexScript cells in Global Table after MTEI import

jon_abbott
Not applicable
241 Views
4 Replies
Message 1 of 5

Evaluating FlexScript cells in Global Table after MTEI import

jon_abbott
Not applicable

[ FlexSim 18.0.3 ]

We have a model where we are using the following syntax to fetch Global Table values:

int value = Table("tableName")["row_name"]["col_name"];

Some of the cells in the table are numbers assigned as numeric data, while others are distributions that are assigned as FlexScript data. This works very well as it evaluates the distribution similar to executetablecell, and is much faster than our previous row and column lookup code.

The issue we are having is when we import table information via MTEI, it changes the cells that are assigned as FlexScript to string data, which prevents the code above from evaluating the distribution. Is there a way to preserve how the cells are assigned to keep them set as FlexScript, or is there some code I can run after the MTEI import that would set each of the string cells to be FlexScript data type instead? Alternatively, if the value is stuck as a string as a result of the MTEI import, is there a "dot syntax" way to perform a type conversion to execute the contents of a string cell (like how executetablecell works)?

@Matthew Gillespie, I've seen you reply to these kinds of questions before so I am tagging you in the hopes that you can help. Thanks in advance!

Accepted solutions (1)
242 Views
4 Replies
Replies (4)
Message 2 of 5

Matthew_Gillespie
Autodesk
Autodesk
Accepted solution

Here is the code to turn a node with string data into a FlexScript node:

treenode theNode;
switch_flexscript(theNode, 1);
buildnodeflexscript(theNode);

If you wanted to toggle all string nodes in a table you could use code like this:

Table table = Table("GlobalTable1");

for(int i = 1; i <= table.numRows; i++) {
	for(int j = 1; j <= table.numCols; j++) {
		treenode theNode = table.cell(i, j);
		if(theNode.dataType == DATATYPE_STRING) {
			switch_flexscript(theNode, 1);
			buildnodeflexscript(theNode);
		}
	}
}

The equivalent of the executetablecell() command in the Table API is the executeCell method:

int value = Table("GlobalTable1").executeCell(2,2);


Matthew Gillespie
FlexSim Software Developer

Message 3 of 5

philboboADSK
Autodesk
Autodesk

You can also execute that code as part of the MTEI so that it happens immediately after the import. Put the code in the Post Import Code in the MTEI window:

10871-post-import-code.png



Phil BoBo
Sr. Manager, Software Development
Message 4 of 5

jon_abbott
Not applicable

Thanks Matthew and Phil! I will give these recommendations a try as soon as I can.

0 Likes
Message 5 of 5

jon_abbott
Not applicable

@Matthew Gillespie and @phil.bobo, thanks for sending these examples. We implemented them into a model and it works great. We did have to set the starting column number to something other than 1 (as we have some string data in some columns that we want to leave as string data), but otherwise the code works exactly as expected. Thanks again.