This video is a 75-minute live coding demonstration teaching five secrets to efficient Revit API development using C#. The instructor aims to save viewers thousands of hours by sharing these techniques, suitable for coders of all experience levels.
InvokeMember: This command allows running external commands from memory, eliminating the need to restart Revit between builds and tests, saving considerable time.Secret number two focuses on rapid iteration in Revit API coding. The instructor demonstrates how to customize a macro to function as an external command, accessible via a ribbon button. The key technique is using the InvokeMember command to execute the external command from memory, allowing for numerous builds and tests without restarting Revit. This significantly speeds up the development process.
The video details implementing Secret #2 (rapid iteration using InvokeMember) as follows:
Create an External Command: The existing macro is modified. A :ExternalCommand is added to the end of the class declaration. The main subroutine is adjusted to accept a UIDocument as an argument. An Execute subroutine is also created; this subroutine is called when the external command is activated from the ribbon. The Execute subroutine then calls the main subroutine.
Create a Ribbon Button: A new module (called "MyRibbon" in the video) is created using the Macro Manager. This module is customized as an external application module, requiring the addition of references to Windows Presentation Foundation, WindowsBase, and System.Xaml. Start-up and shutdown routines are added, along with an external event that calls the previously created macro. An image is added to the button for visual clarity. The resulting add-in file is copied into the Revit Add-ins folder, ensuring it loads automatically.
InvokeMember: The InvokeMember command is used within the code. It enables running the external command directly from memory. This eliminates the need to repeatedly build and restart Revit during the testing phase. The video shows how the build and test process is significantly faster with this implementation. The speaker repeatedly shows a build time of under 2 seconds.
The video provides a live demonstration of these steps, showing the code modifications and the resulting behavior in Revit. Specific code snippets are displayed but not fully transcribed in your provided text. To get the exact code, you would need to watch the video itself.