question

karthik avatar image
1 Like"
karthik asked karthik commented

Export table to any location and save the file in csv format

Hi,

I wanted to export the table "Hrt_Insp_In_rack_Max_cap_WIP" values into to csv file in other folder location not in model directory location.

I need the user to select the location where they can save the csv file. But the csv file name will be preset to data.csv as per the below image.

1686510774935.png

Please help me with this problem. I'm not getting any idea.

Please let me know if your solution works even when I'm running Experimenter (Meaning the user should get the popup to select the file location while running the experimenter).


Thanks in advance

FlexSim 22.1.4
expaorttablefileborweser
1686510774935.png (38.0 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.

Joerg Vogel avatar image Joerg Vogel commented ·
@karthik, you want to delay automatic multithread cpu tasks just to open multiple system save dialogs to decide manually where to store some data?
0 Likes 0 ·
karthik avatar image karthik Joerg Vogel commented ·

No I don't want to delay automatic multithread cpu tasks, @Joerg Vogel I will be asking the user to select the file location only once at the end of the model run i.e., after 30 days.

0 Likes 0 ·
karthik avatar image karthik karthik commented ·

@Joerg Vogel I'm running the model for 30 days. In process flow and I'm creating the token on 30th days to flow to this custom code and wanted the user to get prompted to set the drive location alone not to select any csv files for storing the data, because I wanted my csv file name that is "data" as the name of the csv file to be saved in the user selected folder.

0 Likes 0 ·

1 Answer

·
Vinay S avatar image
3 Likes"
Vinay S answered karthik commented

Hi Karthik,

Create a node in Tools Tree, rename it (Ex: GetFolder).1686556597196.png

Right click on node and add some text data to it, by choosing 'Add Text Data' from Node option.

1686557160482.png

(We'll use this node to store folder location as string).


Add a Model trigger 'On Run Start'.1686556719405.png

Enter this below code in the Code Editor.

getdirbrowse("","Select the folder to export CSV",Model.find("Tools/GetFolder"));

On Run Start, this will Opens a browser window to pick a folder, and the folder location will be stored in the Node: "Tools/GetFolder" as text. You can fetch data by using this code

Model.find("Tools/GetFolder").value;


And to export your table you can use this node value for example like this.

exporttable(Table("GlobalTable1"),(Model.find("Tools/GetFolder").value)+"/data.csv",1,1);

This will export "GlobalTable1" data to 'data.csv' inside the selected folder.


1686556597196.png (16.6 KiB)
1686556719405.png (48.9 KiB)
1686557160482.png (16.2 KiB)
· 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.

karthik avatar image karthik commented ·
Thanks @Vinay S, this method is working great
0 Likes 0 ·

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.