question

shanice.c avatar image
0 Likes"
shanice.c asked shanice.c commented

How to change treenode into Table class?

I have logic that uses different Table in different condition, I'd like to query which Table to write to first.

In this Table, the pointer value is like "/Tools/GlobalTables/T1", which is treenode class.

1646277469028.png


How could I transfer this "/Tools/GlobalTables/T1" into a Table class, then add values into this Table.

Thank you!

testTable.fsm

FlexSim 21.2.0
tables
1646277469028.png (8.5 KiB)
testtable.fsm (29.1 KiB)
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

·
Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered shanice.c commented

Your code is correct, but the T1-T3 tables don't possess any columns.

1646290772880.png

Either set the tables up manually before starting the model, use the reset trigger on the tables for this or utilize the "Table.setSize()" command to adjust the table size directly in your code before writing to it.



1646290772880.png (8.6 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.

shanice.c avatar image shanice.c commented ·

Hi @Felix Möhlmann , thanks for your response. I actually want code doing like how testtable2.fsm works. T1 and T2 Table has 0 row in the beginning. Whenever a token come into customcode, then add a row and fill values into the field.

Now my problem is since I query from Table first, then I get a value in "treenode class". I hope I could transfer this value into "Table class", so that whole thing could work like testtable2.fsm.

You've mentioned T1-T3 tables don't possess any columns. Because the table format has changed after running model. Now I upload the initial model which is same as above problem. After running this model, the column of T1, T2, T3 become zero, also the Table name shows right-side properties pane would disappear. I was confused what mistake there when transfering class.

testtable1.fsm

testtable2.fsm

0 Likes 0 ·
testtable1.fsm (30.4 KiB)
Felix Möhlmann avatar image Felix Möhlmann shanice.c commented ·

The actual table node of a global table is the "data" node inside their variables tree. To write to the global table you would get a path to this node from the object node, then write to it as normally.

int random = duniform(1,3);
treenode ATable = Table("GlobalTable1")[random][2];
treenode dataNode = ATable.find(">variables/data");
Table BTable = dataNode.as(Table);

A different solution would be to write the name of the target table into GlobalTable1, rather than a pointer. Then you could use the name to cast the table into a variable directly.

int random = duniform(1,3);
string tableName = Table("GlobalTable1")[random][2];
Table BTable = Table(tableName);

testtable1_1.fsm

0 Likes 0 ·
testtable1-1.fsm (28.9 KiB)
shanice.c avatar image shanice.c Felix Möhlmann commented ·

@Felix Möhlmann Thank you, both ways are very helpful.

I also try to create treenode table for the first time.

testTransfer.fsm

0 Likes 0 ·
testtransfer.fsm (29.5 KiB)

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.