More On Revit API
This post is a small collection of ideas I’ve been wanting to write down for a while. It is basically a bit of a continuation of this previous post - more Revit API tips for anyone jumping into it.
Truth to be told, at the time I am writing this post, I haven’t been coding Revit API Addins for months (I’ve been doing Desktop apps lately), so if something I write doesn’t make sense, please leave a comment and I will review it. Here it goes:
Hot Reload During Development - Rapid Iteration¶
We all want to modify the code a little bit and immediately jump to the Revit UI and see if it does what we want. But the default setup requires you to close Revit, build the new DLL and open Revit again. It takes time.
For a solution, I would recommend anyone to take a look at Joshua Lumley’s example to achieve rapid iteration (hot reload). I think what is best from his example is that it is pure code (no magic happening in the background), so it opens the door to more learning than when using a pre-built tool for hot reload (e.g. RevitAddInManager).
From what I remember, basically works like this: a single DLL will be “locked” (it might be the one you point to in the addin file). That one you can’t really modify. But that single DLL, using reflection (the “invoke” mentioned by Joshua), can call other DLLs that can be hot-reloaded. Then you end up with at least two projects in your solution: one has the code that will be locked, and the other one/ones will contain code that is called using reflection and hot-reloaded at will.
How to use Revit Lookup¶
Revit Lookup is clearly the must-have tool for developing Revit Addins, but when starting to code for the first time, it doesn’t seem very intuitive. I am going to write a few bullet points below, hoping it will be useful for someone:
- The only command I’ve always used is the “Snoop Selection”. Other parts of the tool might be very useful, but if you only learn to use “Snoop Selection”, it is already a lot of help.
- In this previous post I explain how I use “Snoop Selection” to learn how to set a parameter of a Revit element - Have a look at it, hopefully it makes sense.
- When you open an element with “Snoop Selection”, what you are doing is discovering whatever that element resembles in the Revit API. You are having a look at an object of a Revit API class; therefore, you should be opening the Revit API docs page and taking a look at the class itself as well.
- When you look at the element in Revit Lookup and compare what you see with the class in the API docs, you will see that some information is missing. That’s normal - you will only see in Revit Lookup what can be shown without providing further arguments (see explanation here).
- Sometimes the UI element you click and the class that pops up will not make sense straight away, and that’s normal. I think it is normal to “imagine” how the classes are in the Revit API from only looking at the element in the Revit UI - then, when we open the corresponding class and dig into the docs, sometimes we learn things are very different from what we imagined.
- At the end of the day, when using Revit Lookup, you are, in a way, diving into the Revit API docs. For understanding the Revit API docs, I think “Object Oriented Programming” is something useful to study - Google it, watch a video, or maybe have a look at this book.
Go with Windows Forms¶
I have worked with Revit Addins using WPF. As per this comment, I would recommend anyone to use Windows Forms instead.
Understanding Transform¶
I would look at this video (Joshua again) if I need to understand Transform (it is the only animation I’ve found online showing it work).
Conclusion¶
That’s it for today. I might put together more relevant notes in the future and create another post. If this was useful for you, and you would like something specific to be added in the next post, please don’t hesitate to message or leave a comment.