question

Jouky D avatar image
0 Likes"
Jouky D asked Felix Möhlmann commented

Exporting and Importing csv with object and Array Columns.

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:)

FlexSim 23.2.1
excel importtablesarray
· 8
5 |100000

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

Jouky D avatar image Jouky D commented ·
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 0 ·
Joerg Vogel avatar image Joerg Vogel Jouky D commented ·

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 0 ·
Jouky D avatar image Jouky D Joerg Vogel commented ·

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 0 ·
Show more comments
Jeanette F avatar image Jeanette F ♦♦ commented ·

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 0 ·
Felix Möhlmann avatar image Felix Möhlmann commented ·

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#Method-cloneTo

0 Likes 0 ·
Jouky D avatar image Jouky D Felix Möhlmann commented ·
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 0 ·

1 Answer

Jouky D avatar image
0 Likes"
Jouky D answered Felix Möhlmann commented

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

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

Felix Möhlmann avatar image Felix Möhlmann commented ·
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 0 ·
Jouky D avatar image Jouky D Felix Möhlmann commented ·
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 0 ·
Felix Möhlmann avatar image Felix Möhlmann Jouky D commented ·
Hm, weird that you can't accept the answer. Hi @Jeanette F, could you please accept Jouky's answer?
0 Likes 0 ·