When you develop your own application based on Revit API, there are many things that you need to know which won’t be included in the API help book or somewhere else. We call them tips. We plan to write down the tips we found or other friends found to help API developers.
Today we want to share one tip:
It’s better to write one Document::regenerate in one transaction just before its commit, and remember to re-get Elements, Views etc. after the regenerate if you put these code in one class/function.
Reason:
When document regeneration, many things may be changed including the memory allocated for the Elements/Views etc. So if you still use the Elements/View etc reference after the regenerate, things may go beyond your expectation. Just keep in mind that, the ElementId in document is stable, but the Element reference is not. Simplify the logic in one transaction will make your code easy to understand and less chance to encounter problems, sometimes one change will not be real until one regenerate. So if you found you change doesn’t work, maybe you need call regenerate.
Chinese Version: 点这里。
Comments
Leave a comment