Grasshopper

algorithmic modeling for Rhino

Any idea how can i export points as a .csv file from grasshopper,python component!!!! . . .

Thanks,

Views: 2100

Reply to This

Replies to This Discussion

Salam... Something like this should do it:

Attachments:

Mersi mard,

It's working. thanks a lot.

How is data saved as any other format then xyz points? Would this work if it were number sliders attached as inputs? xyzuv...etc 

You can write anything to a CSV file, although the above script would only work for a list of points (and I think you'd probably have to replace all of the grave accents [`] with single quotes). Let's say you have a hypothetical "5D" point, which would be a point with 5 attributes: X, Y, Z, U, V. All you would have to do to modify the script to compile a CSV file of your 5D points would be to change everything between the parentheses after "write".

fileName.write('pt5D.x' + "," + 'pt5D.y' + "," + 'pt5D.z' + "," + 'pt5D.u' \

+ "," + 'pt5D.v' + "\n") 

This is assuming that your object does indeed have these 5 attributes.

This is it, got me stuck with forgetting to set Type hint set to float 

You can get rid of the for loop altogether as well. With a range from 0 to 1, you're just looping through once, so it doesn't make sense to use a loop in the first place.

you can also use join to make it more readable. These two lines of code does the same as your code.

with open(filepath, 'wb) as outf:

   outf.write(','.join((x, y, z, u, v)) + '\n')

There is also a build-in library in Python for that:

http://docs.python.org/2/library/csv.html

the CVS build-in Library doesnt work for IronPython wich is the version of python that run under Rhino 5 

True. Has anyone found a workaround in python for this? I'm trying to read a file line by line, essentially look up a line in a file by its line number.

is it a csv file? I haven't tested the code but something like this should work for you:

filename = open(yourFileAddress, 'r')

for lineNumber, line in enumerate(filename): 

          print lineNumeber #print the line number

          print line.split(',')  #print the line

filename.close()

Classic.

RSS

Translate

Search Grasshopper

Photos

  • Add Photos
  • View All

© 2017   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service