cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Assign flexscript data type on import

Assign flexscript data type on import

Create a simple method (or self-recognition) to import data as FlexScript type on import. I am running several scenarios where the distributions are updated outside of FlexSim and imported through Excel interface. Every time I import, I have to update the fields as FlexScript before running the scenario.

5 Comments
philboboADSK
Autodesk

You can use the executeCell() command to execute a string datatype cell as FlexScript:

Table("GlobalTable1").executeCell(1,1);

You can also edit the Post Import Code to automatically toggle the cells in a certain column to be FlexScript rather than doing it manually:

10871-post-import-code.png

Table table = Table("GlobalTable1");
int col = 2;
for (int row = 1; row <= table.numRows; row++) {
	switch_flexscript(table.cell(row, col), 1);
}
buildnodeflexscript(table);
kari_payton
Not applicable

Can you explain how to do this for switching to numerical and text? I looked up "switch_numerical" or "switch_text" in the command helper but didn't find these functions. @phil.bobo

philboboADSK
Autodesk
table.cell(1,1).dataType = DATATYPE_NUMBER;
table.cell(1,1).dataType = DATATYPE_STRING;
kari_payton
Not applicable

I used this code and it turned all of the columns to zeros. Any idea what's missing? @phil.bobo

int onreset = param(1); //1 if this code is being called on Reset of the model, 0 otherwise
Table table = Table("JournalTransactions");
int col = 2;
for (int row = 1; row <= table.numRows; row++) {
	
	table.cell(row,col).dataType = DATATYPE_NUMBER;
}
philboboADSK
Autodesk

If you change the dataType, it doesn't preserve or convert the data. If the dataType changes, then the data will be empty.

If you want to preserve or convert the data, you need to do so explicitly.

For example, the following code will convert each cell's string data into a number and set the cell's value to that number:

Table table = Table("GlobalTable1");
int col = 2;
for (int row = 1; row <= table.numRows; row++) {
	Variant previousValue = table.cell(row,col).value;
	if (previousValue.type == VAR_TYPE_STRING)
		table.cell(row,col).value = previousValue.toNum();
}

In this example, any other data types (such as Array, Bundle, Number, Pointer, etc.) are ignored.

Setting the value property sets both the value and its dataType based on the data type of the value you are setting it to.

Can't find what you're looking for? Ask the community or share your knowledge.

Submit Idea