Hi All,
Does anyone know how to export the text data of multiple textdots in one csv file?
Thanks in advance
Hi All,
Does anyone know how to export the text data of multiple textdots in one csv file?
Thanks in advance
Roughly:
Get the text dots
In a list, collect the dot texts via rs.TextDotText()
Write the .csv file line by line using standard python file writing code -
or,
Collect the list of texts into one big string with line breaks and write the whole string at once
Do you need a full example?
Something like:
import rhinoscriptsyntax as rs
def ExportDotsCSV():
dots=rs.GetObjects("Select text dots to export",8192,preselect=True)
if not dots: return
filter = "CSV File (*.csv)|*.csv||"
filename = rs.SaveFileName("Save data file as", filter)
if not filename: return
file = open(filename, "w")
for i,dot in enumerate(dots):
txt=rs.TextDotText(dot)
#don't add separator for last line
if i<len(dots)-1: txt+=","
file.write(txt)
file.close()
ExportDotsCSV()
This makes one big line with all the texts separated by commas.
For Euro CSV, change txt+=","
to txt+=";"
For each item on a separate line change txt+=","
to txt+="\n"
To create one big string and write the whole file at once:
import rhinoscriptsyntax as rs
def ExportDotsCSV():
dots=rs.GetObjects("Select text dots to export",8192,preselect=True)
if not dots: return
filter = "CSV File (*.csv)|*.csv||"
filename = rs.SaveFileName("Save data file as", filter)
if not filename: return
to_write=""
for i,dot in enumerate(dots):
to_write+=rs.TextDotText(dot)
if i<len(dots)-1: to_write+=","
with open(filename, "w") as file: file.write(to_write)
ExportDotsCSV()
Thanks Mitch!
It’s exactly what I was looking for!!