algorithmic modeling for Rhino

Hello community,


I like to share a small C# snippet to constantly print strings asynchrony into a temporary file.

This extension of the Print() method could be used for “debugging”.


When scripting in grasshopper, often there is a situation where logical or geometrical problems occur without causing an exception or compiling error.  A good way to identify such problems is using the Print(…)-method to find out which operations produced the desired result and which did not.


However there is a big problem with it. To find out which parts worked you usually need to go through the whole solution to get the printed strings shown in the out parameter.

So what happens if your solution takes 2 hours to complete or it even crashes in the middle of the calculation? In this situation, it could be useful to have at least a partial list of your Printed statements. With this snipped you can add a line to a temporary file every time the PrintEx() was called.

It isn't maybe so useful for most people, but it also shows how to create events...

There is still a bug in this: After changing something in the script you need to manually restart the solution.

Views: 751

Replies to This Discussion

Nice one Tom! Thumbs up/

This is a great example, very clever, thanks. For my purposes I use something a bit simpler - it appends a line to a log file for every "Print" call without all of the event handling and such. You could easily augment it to generate a temp file path like yours - I like to know where my temp file is so I can check on its progress while the long-running process is running.

void LogPrint(string msg)
    using(var sw = File.AppendText(@"C:\Users\Andheum\Desktop\log.txt"))







  • Add Photos
  • View All

© 2021   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service