Long story short: I am trying to export the list to a file or something equivalent so that I can have the data for post-processing. This is the mesh normal as a list.
Exporting it as a Python object would also be an option, but could someone please let me know how it can be achieved?
I’d recommend using the standard Python pickle module for writing/reading arbitrary data objects/structures to/from disk. Spreadsheets will typically only support primitive data types (integers, floats, strings, bools etc).
Thank you very much for your reply! So I tried to use pickle module but failed because Rhino.Geometry object is not supported outside of grasshopper. Do you have any suggestions on the problem?
Yes you won’t be able to (meaningfully) deserialise RhinoCommon objects outside of Rhino (or maybe all these latest Rhino Compute/Inside developments enables this). Either way, you’ll probably need to more explicitly describe the data pipeline you’re looking to develop, for us to provide appropriate solutions.
My primary objective is to export the mesh data out of the Rhinoceros so that I can use it for postprocessing in Python. I tried to export as CSV but the file does not preserve the format that displays on the Panel (i.e. it just merges into a giant list and I cannot distinguish which vector corresponds to which face). So what I really like to do is to, for example, call the face by its number and the program just spit out the corresponding normal vectors.
In that case, perhaps going with the agnostic JSON format might be a good solution (that way you could also read/write the data in C#, JavaScript etc). Here’s a quick implementation (note there are substantially more efficient ways of going about this in terms of performance, but this is probably more beginner-friendly):
If you need normals, you can access these and add them to the dictionary as well.
Edit: Forgot the indent parameter when dumping the file, which formats the output in the “pretty” JSON style, making it more legible when viewing in a text editor:
import json
#data inputs
key = []
x = key
values = []
y = values
#pack into dict
data = {"key": key, "values": values}
#write data to file
if WriteJSON:
with open(JSONFilePath,"w") as writeFile:
json.dump(data,writeFile,indent=4)
you’ll need to give your python script “tree access” rather than list access so that you can iterate over the branches explicitly rather than implicitly - otherwise the script will simply run multiple times, once per branch.