(Part of the What’s New in the Revit 2010 API series)
The Event section of the API is one area that I believe developers have been hoping for years to see more… In 2010, Autodesk re-writes a bunch of what is there, adds a few more interesting events – but probably leaves out what you were hoping for…
Before and After
The biggest change, both for the re-written events and the new events is that they can receive callbacks either “before” the action or “after” – which is a very nice, mature feature for events. The “before” events enable you to either (1) fix the model before it is saved/printed/etc OR (2) stop the process and ask the user to do something before the action can be performed.
NOTE: for those of you who are thinking immediately about having “alternative interfaces” for something like Document.SaveAs – I think you’ll be disappointed. So far as I can see all of the “before” events are still fired after the user has completed the dialog (i.e. chosen the new SaveAs target file) – but before it actually happens.
User-Driven and API-Driven
I’m not sure that this was the case in the past – but there are notes with the 2010 release that indicate that the events will fire not just when triggered by interactive usage – but also when triggered by the API. I’m not 100% sure if I love that (once we developers all start using them at the same time) – but we’ll see.
Re-written Events
The following events have been re-implemented:
- Document Creation
- Document Opening
- Document Saving
- Document Save As
- Document Closing
- DialogBox showing (Revit 2010 generally uses the newer style “TaskDialog” from WPF, rather than the old-school “MessageBox” of the last 15 years)
The New Events
The new events are:
- File Export
- File Import
- View Printing
- Document Printing
- View Activating
- Document Save to Central
The last one, saving a document to the central file – has some interesting options – including being able to see the exact properties that have been used for the operation, including:
- Compact Central File
- Relinquish Borrowed Elements
- Relinquish Family Worksets
- Relinquish Project Standard Worksets
- Relinquish User Created Worksets
- Save Local File
That said, alas, they are read-only.
In Summary
I know you were hoping for an element-level event. Autodesk knows that you’d like to have it – but there are apparently some complexities and pitfalls to giving us this power (not the least of which is that we could probably cause never-ending cascading update loops).
All in all, though – the events took a good step forward in terms of the maturity of the API. They’re better thought out than before, and they’ll get more usage.
No comments:
Post a Comment