Page 1 of 1

Export Data to a txt-File

Posted: Thursday 07 April, 2016 - 19:04
by jufink
Hello,

I am an ED-beginner. I did the Excel/Active-X Guide and it worked perfectly. My goal is now to write data(for example waiting times in a queue) in a local txt-File, like a log-file. Just add the information to the file.
Are there 4d-script functions or any other atoms that would let me do this?

Re: Export Data to a txt-File

Posted: Monday 11 April, 2016 - 11:32
by HarryBunnik
Hello Jufink,

Have you already looked in the example files? For instance:

..\Documents\Enterprise Dynamics 9\Models\Examples\English\Files\Writing Data.mod

might be help you further. :-)

Cheers,

Harry

Re: Export Data to a txt-File

Posted: Monday 11 April, 2016 - 15:24
by jufink
Harry,
Thank you very much. I looked at your suggested example and it worked!
The data is written into the txt-file and after the 1000 seconds the close-event is triggered and the information is getting saved. Now I ask myself, is there a way to save the information continuously to the file? like every time the Server triggers the event to write, the txt-file is automaticall updated and saved?

I think about triggering all the events every time I write something to the txt-file(open file, write into file, close file. Or is there another solution?

Cheers
Julian

Re: Export Data to a txt-File

Posted: Monday 11 April, 2016 - 16:00
by HarryBunnik
Hallo Julian,

Constantly opening and closing will make it relatively slow. If you open the file at the beginning of the simulation and close it at the end when you're done, you can in between continuously write to it from everywhere in the model. As long as the data that you write away, contains the name of the place where the logging is coming from, you can distinguish in what logging it was. Or am I misunderstanding your problem?

Cheers,

Harry

Re: Export Data to a txt-File

Posted: Tuesday 12 April, 2016 - 10:44
by jufink
Hallo Harry,
thank you very much for your fast and detailed reply. :)
I thought the same thing about constantly closing and opening the file.

My goal is to write and the save the data in 'real-time' to the txt-file.
When I use the example-model the data is written and saved to the txt when the whole simulation has ended. While the simulation is running the file is and stays blank until the end event is triggered and the file gets closed.

Cheers Julian

Re: Export Data to a txt-File

Posted: Tuesday 12 April, 2016 - 14:07
by HarryBunnik
Hallo Julian,

The data is written constantly, but only once the file is closed, the file is finalized and the data becomes visible (Using the command "Fileclose"). If you want to be able to see the data half way your simulation, you'll have to:
  • stop the simulation,
  • close the file,
  • look at the data,
  • close the text file in the editor you're using (most likely this step is not necessary),
  • reopen the file from ED
  • continue running the simulation
Or you'll have to write the data away in a different way (first into a table and flush that table to a .txt file every 1000 rows and start on row 1 of the table again, or use a connection with Excel.

I don't see another option so quickly.

Cheers,

Harry

Re: Export Data to a txt-File

Posted: Wednesday 13 April, 2016 - 12:37
by jufink
Hallo Harry,

thank you again for your helpful answer.

Cheers
Julian