Export Data to a txt-File

All topics on coding 4Dscript in Enterprise Dynamics.
Post Reply
jufink
Posts: 4
Joined: Monday 04 April, 2016 - 18:12

Export Data to a txt-File

Post 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?
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: Export Data to a txt-File

Post 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
jufink
Posts: 4
Joined: Monday 04 April, 2016 - 18:12

Re: Export Data to a txt-File

Post 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
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: Export Data to a txt-File

Post 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
jufink
Posts: 4
Joined: Monday 04 April, 2016 - 18:12

Re: Export Data to a txt-File

Post 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
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: Export Data to a txt-File

Post 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
jufink
Posts: 4
Joined: Monday 04 April, 2016 - 18:12

Re: Export Data to a txt-File

Post by jufink »

Hallo Harry,

thank you again for your helpful answer.

Cheers
Julian
Post Reply