See if below script helps. When the event is added it prints a message to the command line after every save. Instead of printing the text you could add your code to launch your script for the CSV export. To disable the event, just run the script again.
Thank you, it works very well on a small model, but with a bigger one, it doesn’t…
It seems that the model saving takes a long time and then the script is forgotten or can’t be treated in the same process. Do you know a way to check if saving is complete before launching the script?
you could also try to save the CSV before saving the document using BeginSaveDocument. Alternatively you might run your code in the idle event, which gets continously fired after all other events are done. Note that you need to implement some checks to exit the idle event then. Maybe setup the idle event in the BeginSaveDocument event, then let the idle event remove itself once fired.
There is also this interface for the idle event which allows to run a script and define an interval:
I set you’re script at the opening of my Rhino session. So every time I save a model, it checks if the model is correct and runs the CSV Export.
But I noticed that the export was also triggered when using other scripts. It seems that the BeginSaveDocument event is raised by other functions.
By debugging, I’ve identified that it comes from this line :
Do you know something about this ? How can I avoid it ?
No. I found that when using BeginSaveDocument event the event gets triggered twice after using CopyToClipboard. Next i tried to find the last command used with rs.LastCommandName() from the event code, but that does not seem to work. I guess the command must have been completed to appear in that list. When the first event gets fired, it still runs, so what the LastCommandName returns is the previous command before CopyToClipboard.
Below seems to work by setting up an idle event in the BeginSaveDocument event. You can check the last command name in the idle event, then decide to export your csv or not. At the end of the idle event, let the event remove itself: