question

Jon Abbott avatar image
1 Like"
Jon Abbott asked Jon Abbott commented

Evaluating FlexScript cells in Global Table after MTEI import

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!

FlexSim 18.0.3
flexscriptstringmtei
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

·
Matthew Gillespie avatar image
2 Likes"
Matthew Gillespie answered Jon Abbott commented

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);
· 3
5 |100000

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

Phil BoBo avatar image Phil BoBo ♦♦ commented ·

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:

1 Like 1 ·
Jon Abbott avatar image Jon Abbott commented ·

@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.

1 Like 1 ·
Jon Abbott avatar image Jon Abbott commented ·

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

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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