A friend emailed with several valid suggestions about how to make the code in the Duplicate Mark example more production-quality. Specifically, he suggested:
1. I would get the list of elements outside of the foreach loop
2. I would not start a transaction if the list is empty
3. I would also do not create the markValues list unless I found doors
4. I would not attempt to commit the transaction unless I changed anything
5. It seems the algorithm would allow adding asterisks to already marked doors (like: “1***) if you run the macro more than once.
6. It also seems that it would not work if you have more than one different door with the same tag. You would end up with one untouched tag, and the rest marked with an asterisk even though those other doors are also different.
He is correct about all of these, and I’ve made some changes in the code of the post below to reflect these. At the same time, I guess I should clarify my intentions for this blog.
What I think would be interesting for me and you is to explore many different questions where we investigate if the Revit API can do certain tasks, and if so, how. I’d like to share source code to demonstrate the use of the key classes and methods to achieve the goal. I will strive to use good coding practices and write code that is clear and easily understood by people with a range of programming and Revit API experience.
Another way of saying it is that this will be proof-of-concept / prototype code and not production code. The code will work in a simple “happy path” scenario, but there will certainly be situations with complex geometry, edge cases, and other situations where it won’t work as presented here.
There are two reasons for doing this. One, the code samples will be a lot longer and more complex for readers to follow if they are full of error handling, try/catch, and special checking for various geometries. Second, it obviously takes a lot longer to write all that extra code and consider all the special cases. If you’d like to hire me to take one of these prototypes to production-quality of course I will be happy to do so.
Does this make sense and seem reasonable? Please leave a comment and let me know.