Hello Everyone,
Is there a way to record and display the solution runtime to have an idea on how long a solution ran if overnight. I know the bottom right will show this, but sometimes it get overwritten. I know each component can show this as well, but again I was wondering if there was a way to extract this as text for reference or something of the sort.
Thanks!
-Emmanuel
There should be a property in GH_Document
that calculates this value but this should also do it.
import Grasshopper
import System.TimeSpan as ts
# create a 0 timespan
total_time = ts()
# get current document
doc = ghenv.Component.OnPingDocument()
# add process time of all components together
for comp in doc.Objects:
total_time += comp.ProcessorTime
# remove the time that took to run this component itself
total_time -= ghenv.Component.ProcessorTime
print(total_time)
Thank you Mostapha for that quick response, however I am getting an error. I have tried several workflows but with the same error.
See attached and thanks!
I assumed all the objects have ProcessTime
attribute. Turns out groups don’t. Try the modified version:
import Grasshopper
import System.TimeSpan as ts
# create a 0 timespan
total_time = ts()
# get current document
doc = ghenv.Component.OnPingDocument()
# add process time of all components together
for comp in doc.Objects:
if not hasattr(comp, 'ProcessorTime'):
continue
total_time += comp.ProcessorTime
# remove the time that took to run this component itself
total_time -= ghenv.Component.ProcessorTime
print(total_time)
1 Like
Hey Mostapha,
Sorry if this is a simple answer but I am not that familiar with python. The code seemed to have worked, however I just ran a workflow that was “16.6 minutes” but the component seems to have keep the previous time. Does it have to refresh separately?
Yes. The component only runs if there is a change in inputs. You can connect the output from totalSunlightHours to x input and that should trigger a new calculation every time that sunlight-hours study is finished.