Write to Text File

Lately I've found myself jotting down and formatting notes in Grasshopper then exporting to a text file. (If this is strange to you, I understand completely.) So I've written a quick script making that workflow a bit easier. I know there are other codes out there, but I thought it might be interesting to share nonetheless.

There are some simple built-in safety protocols. It checks for an existing file path first then proceeds with the exporting process. If the specified file contains data the user is prompted with a warning, asking him/her to allow an overwrite or specify a new path.

It also works with CSV files. You will need GHPython.

You're welcome to download it here. Image of it in use below.

Best,
/SPM

EDIT 05/2016: The above file now includes the latest script with the additional functions (append, relative path, etc.).

  • 筑梦NARUTO

    Thanks for sharing

  • Matt Gaydon

    Guessing you know when you write click on a panel you can click stream contents and set file path to stream to. Only down side is it will stream them in real time with the only way to stop the over ride is right click the panel and click the stream contents icon again to stop it.

    P.s I like the idea of a boolean switch to stop and start writing. As means you can design things then break the stream and use the saved data for something else. Guess you can do it with Data Dam though that does not have a switch and must be done manually.

  • Stephen Maher

    Matt,

    My thoughts exactly. I was looking for a more user-friendly way to export text. The script allows me to stream data in real time or not. Fits better with my workflow.

    /SPM

    P.S. Just finished a bit of code that prompts the user to choose a file upon setting "write" to "True." This cut the code a few lines and removes the '"file" input, but may not be desirable if the user is constantly overwriting the same file.

  • Christian Schmidts

    The component is a useful alternative to stream content option of the panel.

    But I was even more excited component you have 'hidden' which shows you the plug ins used in a definition. That is really helpful if you hand out definitions to people!

  • Stephen Maher

    Christian,

    That code is an adapted version of Giulio and Brian's (see discussion here), which is why I credit them in the script.

    The code pings the GH Document, so if you're passing along a definition to someone who doesn't have a particular plugin the file uses, it will not display in the [Panel]. But the user will still be prompted with the "Unrecognized Objects" warning.

    /SPM

  • Stephen Maher

    Now with an 'append' option. Should have thought of that before.

    /SPM

  • Nick Devlin

    Hi Stephen, 

    Is there a link to the updated version with the append function? I downloaded from the link in the original post but it includes the overwrite function instead? Many thanks - this looks like just what I need. 

    regards

    Nick

  • Stephen Maher

    Hey, Nick. Sure thing; I just updated the file in the post. I hope it helps!
    /SPM

  • Nick Devlin

    thanks Stephen.

  • Patrick Monte

    This would be really useful to me because I am doing some operations that max out the panel character limit. I've tried writing to excel, but there again hit cell character limits, so I really need to be able to write a text file directly. I seem to be getting encoding errors though:

    1. Solution exception:'ascii' codec can't encode character '\u2019' in position 54

  • Stephen Maher

    Hey Patrick, mind posting your file so I can take a look? Or shoot me a DM with the file.
    /SPM

  • tsaohy

    Hi Stephen. Thanks for sharing this GH file. However, the gcode one doesn't work for me, I'm not sure why, there is no any .gcode file showing up. Thx for helping.

  • Stephen Maher

    tsaohy – What .gcode are you referring to? This is a Python code that only requires the GHPython scripting component.

    Are you trying to write a .gcode file with this script?

    /SPM

  • Philippe HAMON

    hi, in the original data set, the text has only got "CRLF" hidden character:

    but in the exported data, i find new characters "CR" added:

     it's annoying, because the CAM software can't directly open the exported file "syntax error", do I miss something?

  • Stephen Maher

    Philippe – I've never tried using this particular script with a CIX file. Do you mind posting the file so I can take a look?