write multiline text to file

 

hi

I'm looking for a solution to write multiline text to a text file, similar to writing a log. The goal is to log timecodes when some triggers are triggered. As a temporary solution, I'm sending lines to the log as messages and copy/paste it to a text file after the show, but it would be more convenient (and safe:)) to write it to a multiline text file.


The desired output could be for example:
trigger1: 00:00:01
trigger2: 00:00:05




thanks,
Bence

   benceb

 
Profile Image
EricWest
  -  

Hi Bence.

I think I'd go for a little script node in this case. Something like:

--$ inMessage text
--$ inWrite trigger

--$ outLog text

TheFile = [[C:\TEMP\test.txt]]

if inWrite == true then
    outLog = inMessage
    -- Opens a file in append mode
    file = io.open(TheFile, "a")
    -- sets the default output file as test.lua
    io.output(file)
    -- appends a word test to the last line of the file
    io.write(inMessage .. '\n')
    -- closes the open file
    io.close(file)
end
should do the trick .. :-)
 
Profile Image
benceb
  -  

Ah, I didn't think about a script node :)
Thank you, that did it!

 
Profile Image
benceb
  -  

Just to share it, it might help someone. Here is the final script with some basic formatting and saving the log to the Desktop:

--$ inMarker text
--$ inTime text
--$ inWrite trigger

--$ outLog text

filepath = os.getenv ("UserProfile")

TheFile = filepath .. [[\Desktop\axi_trigger.txt]]

 
if inWrite == true then
    outLog = inMarker .. ":" .. inTime
    -- Opens a file in append mode
    file = io.open(TheFile, "a")
    -- sets the output file
    io.output(file)
    -- appends a string to the last line of the file

    if inMarker == "2" then
        io.write('\n')
        io.write(os.date('%A, %B %d %Y at %I:%M:%S %p') .. '\n')
    end

    io.write(outLog .. '\n')
    -- closes the open file
    io.close(file)
end
 
Profile Image
EricWest
  -  

Thanks for sharing mate!

;