Hello everyone! I created a part of a Dynamo script that should be placed inside each script to collect usage statistics (name of the Project file, user name, execution time, errors, etc.) and export it to an Excel file. I was inspired by the following article:
and by the following topic (here is an example of how to collect all errors from a current Dynamo workspace by a WinForms app):
So, I created a dummy script for testing that:
performs some dummy calculations and gets its execution time,
then gathers other usage data and puts it into a list,
transfers the list of data to a Python script node that calls a hidden WinForms app,
that app retrieves all errors from Dynamo when a necessary event occurs,
appends error data to the usage data list,
exports all data from the list to an Excel file,
and finally closes and disposes of the WinForms app.
It works, but with some issues. The problem is that it runs and writes to an Excel file multiple times instead of once (through Dynamo Editor or Dynamo Player - it doesnât matter). And each time I run my script, the number of its executions increases by one. So, it writes duplicated information from all previous runs from the current Dynamo Editorâs or Dynamo Playerâs session. Could anyone have a look inside my Dynamo script and find what I did wrong?
Can you post a screenshot of your graph with all the node preview bubbles pinned so we have an idea of what itâs doing?
If it runs an extra time with each execution and duplicates data then it would seem like somewhere youâre either reading that data each time you write it or youâre otherwise allowing each âpushâ to refresh an input in your graph and force a new run.
I have attached my script at the end of my post)
I suspect that the problem could be due to a memory leak. The issues might be with the unsubscribing from an event or transferring data into WinForms instance using global variables. But Iâm not sure with that
Tried it in Dynamo sandbox and it errored out as youâre calling Dynamo for revit methods exclusively but I couldnât have known that until I opened up your graph, and so your error doesnât reproduce there.
So I tried in Revit, but I didnât have Ironpython 2 on my Revit installation so that took a bit, and I donât have what I think is supposed to be your excel file (no extension on the file path so i can only guess) so when it runs I canât see any dataI canât confirm double execution. All in Iâm now 25 minutes into trying to make this work with nothing to show for it.
My gut tells me the error is in your winforms that is launching in hidden mode⌠which means users will get a window that will lock up excel but not actually be visible⌠and to make maters worse it doesnât appear to close⌠ever. And as you have an event to âlistenâ for the dynamo instance to complete executing, the win-form is going to hand open and continue to write out to the excel file over and over and over again. I can now trigger 10 write outs concurrently.
Python scripting isnât a valid path for this IMO, doubly so with the permanent IronPython2 dependency youâve baked in. If you want to stay in scripting languages, move to a âwrite to csvâ node and abandon tracking warnings by interrogating the graph (no real value in that anyway) and instead build your tools to report when they have a issue.
If you really want the âread the graph statusâ you should transition to a C# view extension that you deploy locally or via package manager. That will ensure that Dynamo queries the data only once after the run complete event is triggered, and writes out from there - you can look up Binoculars for Dynamo on the blog for an example. Starting there and re-working the code will have the added benefit what youâre after wonât be limited to Dynamo for Revit when youâre done (Dynamo has itâs own username which inherits the same username as Revit, etc.).