All I want to do is export multi-line coordinates to a text file …
What am I doing wrong?
Exporting coordinates.gh (12.8 KB)
All I want to do is export multi-line coordinates to a text file …
What am I doing wrong?
Exporting coordinates.gh (12.8 KB)
Your text panel has an extra empty line that causes the red component and error message, but we can ignore that.
text = ''
for t in txt:
text += (str(t) + '\n')
a = text
f = open(fName, 'w')
f.write(text)
f.close()
P.S. Or more simply:
text = ''
for t in txt:
text += t + '\n'
f = open(fName, 'w')
f.write(text)
f.close()
Exporting coordinates_2023_Aug8b.gh (14.2 KB)
@Joseph_Oster I get this runtime error?
Try changing the filename to include a folder that is not in the ‘/Program Files’ directory? For example:
C:\Users\userName\Downloads\gh\points3.csv
P.S. You could include date/time in the filename:
import datetime
now = datetime.datetime.now()
Y = now.year
M = now.month
D = now.day
h = now.hour
m = now.minute
s = now.second
@Joseph_Oster Thank you for the date/time suggestion!
@Joseph_Oster that worked! Thanks again
@Joseph_Oster not sure what I’m doing wrong, trying to include the date and time but get an error.
Export file with date and time.gh (12.4 KB)
Runtime error (NotSupportedException): The given path’s format is not supported.
Sounds plain enough to me. Maybe the colons (‘:’) or spaces or starting a filename with numbers?
C:\Users\Administrator\Documents\2023-08-10 08:48:03 file to export.txt
Keep trying, you don’t need me to figure this out. Looks way more complicated than necessary. And you don’t have any points to export?
This works: (apparently it was the colons)
C:\Users\josep\Documents\file to export 2023-08-10 08_48_03.txt
This also works:
C:\Users\josep\Documents\2023-08-10 08_48_03 file to export.txt
@Joseph_Oster Thank you! and Thank you for the words of encouragement!!
import datetime
now = datetime.datetime.now()
def padLeft(num, len = 2):
return str(num).zfill(2)
fNameTD = fName + '_' + padLeft(now.year) + '_' + padLeft(now.month) + '_' + padLeft(now.day) + '_' + padLeft(now.hour) + '_' + padLeft(now.minute) + '_' + padLeft(now.second) + '.' + suffix