I recently received several requests for a migration of the macro samples provided in the
The project included in the Revit 2017 SDK miraculously is still based on Revit 2013 pre-release version, according to the update message displayed when opening it:
Unfortunately, after the update process, the macro samples included in the project still cannot be executed successfully due to a number small enhancements made in the intervening years to some of the Revit API function calls and signatures.
Question: In reviewing the SDK documentation and various web-based Autodesk help resources, I have yet to find a resolution to this issue. The sample Revit project located in the Revit 2016 SDK 'Macro Samples\Revit_Macro_Samples.rvt' project appears to be a Revit 2013 project. After opening and upgrading the document for use in Revit 2016, I attempted to run a macro. The macro manager shows that there are problems with the macros:
Upon editing and attempting to build, debug output indicates many critical errors, cf. build.txt, which appear to result from various class methods that have been deprecated somewhere between Revit 2013 and Revit 2016.
Is there a functional macro sample Revit project available somewhere? Am I approaching this incorrectly, somehow? The Autodesk help makes multiple mentions of the necessity to upgrade, and sometimes manually edit the macros so that they will function. However, implementing the deprecated methods according to the 2016 API would require significant changes, time, and effort.
Is it better to ignore this sample document and use some other web resources for learning the foundations of Revit macro creation? Are there good resources for Python-based macro development? It appears that newly created Python macros are automagically populated with sample macros that can be successfully built. However, creation of new C# and VB.Net do NOT offer similar buildable samples.
I'm incredibly confused by the SDK and various documentation inconsistencies, and various web searches do not offer any solutions. Thanks in advance for any insights.
Answer: Thank you for your report and very sorry about your confusion.
I hope that the material for getting started with the Revit API in its non-macro incarnation is a bit clearer.
The macro environment should be simpler to use. I am sorry to hear that the samples are broken, though.
I checked, and we do indeed have an existing change request number REVIT-93253 SDK macro samples cause build errors due to obsolete API for this issue.
I hope this trouble getting started with the Revit macros does not put you off and that you find a good, fruitful, productive and fun way forward with no further frustrations.
I don't know if this is the right place to share this but since it's the most responsive blog about the subject (thanks to you) I thought I'd give it a go here.
I've noticed that the macro demonstration document
Revit_Macro_Samples.rvtlocated in Revit SDK macro samples folder is way out dated (its actually still in 2013 format), and I don't know if anyone have already did an upgrade on it so I took the liberty of doing that by eliminating all the errors that prevented the code form compiling, this might be useful for new comers (like me) as a start point for learning the magic of Revit API!
Now just to be clear, I did not optimise the code to make the best use of the new API features, all I did is going through the errors, fixing them one by one and trying to add/change the least amount of code, so there might be some sluggish bits of code that could obviously be made better, but hey, let the never lazy cast the first stone! I'm not confident of doing the same for the other macro sample documents (MEP and Family macro samples) as I haven't tinkered with these environments much during my API play time.
You can find the upgraded project file on Google drive.
All macros tested and seem to work fine.
Ever so many thanks to Sam for his migration work, repairing all the issues, and sharing the updated version!
In order to easily display the migration modification applied by Sam, I created the Revit_Macro_Samples GitHub repository.
I initially populated it with the C# source code of the original Revit 2013 pre-release version of the macros provided in the Revit 2017 SDK.
I did so by copying all the files from the temporary folder created when editing them in SharpDevelop into the local clone of the repo:
I created the release 2013.0.0.1 to tag that version as the starting point.
Next, I opened the macros in Sam's updated project in a similar fashion, and copied them over the original version; they were located in another temporary SharpDevelop folder:
That version is tagged as release 2017.0.0.0.
You can view the differences by using the GitHub functionality to compare changes 2013.0.0.1...2017.0.0.0.
I stored a copy of Sam's upgraded project file Revit_Macro_Samples_2017.rvt in the GitHub repo as well, to enable you to open it in Revit right away.
I hope this helps, and many thanks once again to Sam for his helpful work!