PVA avatar image
PVA asked Natalie White commented

How to change datatype of a Table from Bundle to Number through script?

I have taken clone of Table1 in bundle datatype as Table2..

Now i want to change Table2 to Number datatype

FlexSim 23.1.2
using codebundle datatable datatype
· 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.

Natalie White avatar image Natalie White commented ·

Hi @PVA, was one of Jason Lightfoot's or Carter Walch's answers helpful? If so, please click the "Accept" button at the bottom of the one that best answers your question. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always comment back to reopen your question.

0 Likes 0 ·
Carter Walch avatar image
Carter Walch answered Carter Walch edited

Hi @PVA ,


You can convert the table it to a treenode and then use the 'dataType' property of the treenode class.

See Jason's answer above for an updated solution.

treenode DataNode = Table("GlobalTable2").as(treenode);
print(DataNode.dataType); // tests to see current data type
DataNode.dataType = DATATYPE_NUMBER ; // set data type to Number
print(DataNode.dataType); // test to confirm new datatype

The datatype macros can be found here


Note: changing the datatype to certain datatypes may change your table. To reset it, simply run the code to set back to the original datatype.

This post may also be helpful in testing the datatype of table nodes

1686932588043.png (52.7 KiB)
tabledatatypes.fsm (25.5 KiB)
· 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.

PVA avatar image PVA commented ·

Hi Carter,

Thank you for your answer. But it hasn't completely solved my problem. I'm trying to duplicate a bundle table and convert the datatype from bundle to integer. I'm attaching the model FYR.

Thank you.tabledatatypes.fsm

0 Likes 0 ·
tabledatatypes.fsm (25.6 KiB)
Arun Kr avatar image Arun Kr PVA commented ·
You are trying to make the table a bundle type or making each cell type as bundle.
0 Likes 0 ·
Felix Möhlmann avatar image Felix Möhlmann PVA commented ·

I'm assuming you want to change the individual table cells from arrays to numbers? (A bundle is a different data structure for the entire table)

For that you can either use Table.setSize() and overwrite the previous values. But this will also remove any row and column headers.

Alternatively you can loop through all cells and change their data type individually.

Table table2 = Table("GlobalTable2");
// This also resets headers table2.setSize(table2.numRows, table2.numCols, DATATYPE_NUMBER, 1); // Loop through cells instead for(int row = 1; row <= table2.numRows; row++) {     for(int col = 1; col <= table2.numCols; col++)     {         table2.cell(row, col).dataType = DATATYPE_NUMBER;     } }
0 Likes 0 ·
Jason Lightfoot avatar image
1 Like"
Jason Lightfoot answered Jason Lightfoot edited

You can't change a table (a structure of related data values stored as a bundle or nested treenodes) to a single number and retain the data.

When you have bundle data in a treenode table's cell, you can simply overwrite the cell data with a new variant:


If anyone finding this post wishes to toggle between treenode-based and bundle table types here's some updated code showing an example data node that is a cell within a global table (first line - this was the case in the orginal poster's model)

treenode data=Table("GlobalTable2").cell(4,1);   //Global table data or other data node
int isGlobalTable=classobject(data.up)==library().find("?GlobalTable");
treenode newData;
if(getdatatype(data) != DATATYPE_BUNDLE) {
    newData = nodeinsertafter(data);
    nodeadddata(newData, DATATYPE_BUNDLE);
else if (isGlobalTable) //Copy from the library so we get our TableHeader node
   newData = createcopy(library().find("?GlobalTable>variables/data"), data.up);
else {   //just a node somewhere
     newData = nodeinsertafter(data);
     newData.value="<Treenode Table>";   // so a user can see the node contains table structure
createcopy(newData,data,1,0,0,1);  // this preserves any pointers to the table that already existed in the model
5 |100000

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