@pascal.fragnoud , if I tries yours I have next:
@lrose, with your script I have this:
ugh, sorry.
the line that is adding the data values needs to convert to string
csv = '\n' + ','.join([str(value) for value in tagValues])
Right sorry, I was expecting your data to be several rows, but it’s actually just one (I should read things more carefully, but who has that kind of time on their hands ? :D)
@pascal.fragnoud, no problem, you are already a big big help :)!
@lrose , The problem now is I do not have any headers more. Also 1 roll is 2 times in my CSV :).
So I think that we are almost there. The only thing is the headers and that he copy 2 times the same roll
Try this one:
tagPaths = ["[Bontexgeo Kft]Rol lengte laatste rol (m)", "[Bontexgeo Kft]Gewicht laatste Rol (kg)"]
tagValues = [qValue.value for qValue in system.tag.readBlocking(tagPaths)]
header = ["Datum", "Tijd", "LENGTE", "GEWICHT"]
now = system.date.now()
fileName = r"D:\TIS_TEST_{}.csv".format(system.date.format(now, "yyMMdd"))
showHeaders = not system.file.fileExists(fileName)
data = [system.date.format(now,"dd/MM/yyyy"), system.date.format(now, "HH:mm:ss")] + tagValues
dataset = system.dataset.toDataSet(header, [data])
csv = system.dataset.toCSV(dataset, showHeaders)
system.file.writeFile(fileName, csv, True)
system.tag.writeBlocking([str(event.getTagPath())], [0])
@pascal.fragnoud, Thanks, but again the same problem with the strange descriptions:
The thing is, this adds the headers if the file doesn't already exist. Which may or may not be a reliable solution.
If you don't expect to manually manipulate the file, it should be fine.
If you want to be a bit more cautious, I'll suggest 2 methods:
Yes sorry I forgot to change one line, try the edited version.
Though that’s a problem for which I already suggested a solution, you could try it yourself :X
@pascal.fragnoud , Yes but like I say, it needs to be very basic. To be honost, I am not very good in this things. Probably you already noticed that :D.
So, for me is it sometimes Chinese.
I’ll explain in a different way:
Those scripts, both @lrose’s and mine, assume you’re not messing with the file. But in your case, you probably already had a file. Which means that, when evaluating whether to put the headers in the csv or not, by checking if the file already existed, it failed, expecting the existing file to already have headers.
If you delete the file, I expect the next one created to be formatted properly.
@pascal.fragnoud, Ok but now I have my headers and everything. I only do not understand why I have 1 roll 2 times. Before it was not like this.
I already deleted the file. I am working with your script.
So, if I understand, there is no solution for this?
Thanks!
Make sure you are properly filtering the tag change event.
Look at the script I provided when I suggested that you move to a tag change event.
if not initialChange and newValue.getValue():
This is important, because it prevents the script from running when you intentionally reset it at the end
Hi all,
Sorry for the late responds.
I have a nice CSV file now.
Thanks for all the help.