Exporting and Importing csv with object and Array Columns.

Exporting and Importing csv with object and Array Columns.

jouky_d
Not applicable
554 Views
12 Replies
Message 1 of 13

Exporting and Importing csv with object and Array Columns.

jouky_d
Not applicable

[ FlexSim 23.2.1 ]

Hello everyone,


I tried to export to a csv file a table with different column types: strings, integers, doubles, OBJECTS, ARRAYS of arrays, etc. All the columns are exported fine except the objects and the arrays of arrays.


I want to re-import that table into FlexSim again to avoid calculate the table again after the reset. But the values are imported as string, e.g.

array: Array[8]: {Array[2]: {1.000000, 4.000000}, Array[2]: {1.000000, 4.000000}, Array[2]: {1.000000, 4.000000}, Array[2]: {1.000000, 4.000000}, Array[2]: {1.000000, 4.000000}, Array[2]: {1.000000, 4.000000}, Array[2]: {1.000000, 4.000000}, Array[2]: {1.000000, 4.000000}}


Is there a way to export and import correctly? If not, maybe I could save the table on a specific moment to reset the table on that values?


Thank you:)

0 Likes
Accepted solutions (1)
555 Views
12 Replies
Replies (12)
Message 2 of 13

jouky_d
Not applicable
And no, I cannot do the table in a separate script because I want to create it during the simulation and depending on some characteristics of the simulation.
0 Likes
Message 3 of 13

Jeanette_Fullmer
Community Manager
Community Manager

Hi @Jouky D,

Thank you for contributing to our community! We couldn't identify a maintained license or subscription linked to your account.

You may need to update your profile information to identify yourself as a license owner or their associate. Check out our article for how to ensure you receive timely support. If you update your profile comment back to let us know - we'll adjust the priority of your post accordingly.

If your current license is expired, please contact your local distributor to renew.

0 Likes
Message 4 of 13

joerg_vogel_HsH
Mentor
Mentor

Let me assume that there are some restrictions in csv file data: strings and numbers. Maybe you can create a string that looks like an array of arrays, that an input interpreter can resolve into an array of arrays.

My fault: There seems to be a more sophistic problem with excel data in a structure of arrays in arrays. Perhaps you think about a different export variant like saving a treenode structure in xml data to your disk.

0 Likes
Message 5 of 13

jouky_d
Not applicable

It's interesting what you propose about exporting the node in xml. Do you know a way to export it and import it using FlexScript? I know there are cmdsavetree and cmdloadtree functions. However, when I export and import using those codes it builds the following treenode:

1720506933549.png
However, when I import using right click of the mouse (Save Node As and Load Into Node) it builds an Object node:
1720507031202.png

0 Likes
Message 6 of 13

moehlmann_fe
Advocate
Advocate

Can you give some more information about what you want to do with the data? Will it be imported into a different model or the same one? Because if it's the same one you could just clone it to a separate table (global table or even some custom node in the model tree if it should not be visible in the toolbox).

https://docs.flexsim.com/en/24.0/Reference/CodingInFlexSim/FlexScriptAPIReference/Data/Table.html#Me...

0 Likes
Message 7 of 13

jouky_d
Not applicable
Hello Felix!


It is the same model. I want to not build the same table every time I run the simulation because it takes 5 min to build it. This table has 800.000 cells including arrays of arrays, so for model speed and not collapse RAM, I guess is better to export and import the node or the table instead of having a 800.000 useless values during the simulations. What do you think?

Maybe I am wrong, but I thing the better way is to export and import treenode or resetting the table values at the time I need to save that table. But we cannot put "Reset Values" on a table, we need another table as you propose. I am trying to do cmdload and cmdsave treenodes it seems it works.

0 Likes
Message 8 of 13

moehlmann_fe
Advocate
Advocate

It looks like you are saving different nodes here. A global table is stored as an object node. The data of the table is stored in the "data" node under variables.

1720508537206.png

The table constructor "Table(tableName)" will access the data node. So if you used something like "cmdsavetree(Table(tableName), path)", it would save and later load the data node.

In your manual try you probably saved the object node.

0 Likes
Message 9 of 13

jouky_d
Not applicable
That was it!
0 Likes
Message 10 of 13

jouky_d
Not applicable
Accepted solution

@Felix Möhlmann and @Joerg Vogel solved it! Thank you! (I don't know why, I can't accept your responses). I used:

- Exporting the Table:

string filename = modeldir().replace("/","\\",1) + "SlotsNode.fsx";

treenode node = Table("Slots");

cmdsavetree(node, filename);


- Importing the Table:

cmdloadtree(node, filename);


It is useful if you table is large. Importing a treenode takes around 6-7 seconds. So if your time computing the table is larger than that, it is useful to apply it. If not, don't waste your time or try another way.

0 Likes
Message 11 of 13

moehlmann_fe
Advocate
Advocate
Our posts up to this point have been comments under the question, not answers, since we were only discussing possibilities or asking for clarification. "Answers" should present a complete solution. So it would be good if you edit yours to include the steps you took to solve the issue so other users can learn from it. Then accept your own answer.

Regarding your latest comment. I tested restoring a table with 800.000 cells (about 2MB of data, yours is probably larger) using both approaches, saving and loading with a separate file and creating a copy directly in the model. Speed wise I didn't notice much of a difference. The downside to having a duplicate table in the model is that the file size would be larger and saving/loading the model will take a bit longer.

0 Likes
Message 12 of 13

jouky_d
Not applicable
Done!


However, I use Table("Slots") and it may cause the problem of taking the data node and not all the node, I don't know how to export it correctly. It works to me now, because I use the old node, but maybe someone wants to import it into a new node.

Thank you! (I still cannot accept my own answer I don't know why)
0 Likes
Message 13 of 13

moehlmann_fe
Advocate
Advocate
Hm, weird that you can't accept the answer. Hi @Jeanette F, could you please accept Jouky's answer?
0 Likes