Imagine if coding a Revit add-in was less of a chore and more of a conversation with a knowledgeable friend who is also a good coder. That's precisely what unfolded in a recent foray with ChatGPT. Let's dive into how this tool transformed a coding task from tedious to terrific.
The Room Height Conundrum
During a recent open Q&A session in the Revit Add-in Academy, a practical challenge emerged: how can we automate setting room heights in Revit to align with their actual ceiling heights? Usually, Revit sets room heights to a default of 8 feet, regardless of where the ceiling is located in the room.
The issue is that ceilings don't automatically know which rooms they are located in. Similarly, rooms don't know anything about the ceilings they contain. You can manually adjust the room height to match the ceiling height. But there are better uses of our time, right?
ChatGPT to the Rescue
The paid version of ChatGPT allows you to create your own GPTs. A GPT is a custom version of ChatGPT that combines specific knowledge and instructions. I made a GPT called "Revit Add-in Expert." This GPT uses the Revit API documentation and other websites, including the Building Coder blog and the Autodesk Revit API forums, as knowledge sources.
The advantage of a custom GPT is that it limits its reach to specific documents and/or knowledge sources. This (hopefully) limits the likelihood that the GPT will generate false answers or "hallucinations." Before the latest update, one big problem I had with ChatGPT was that it would make up parts of the Revit API. I would paste the code into Visual Studio only to be told that the Revit API didn't contain that method or property. It was frustrating, to say the least! However, with my custom GPT, this is much less likely to happen.
The Collaborative Process
With my "Revit Add-in Expert" GPT ready to use, I tasked it with generating the code for the room height challenge. What followed was an engaging back-and-forth – a blend of clarifications, suggestions, and refinements. I started by asking it to create a Revit add-in that updates the height of the selected room to match the height of the ceiling in that room. The GPT responded with a generic overview of the process, outlining key components and giving me some best practices. I then asked it to generate some code. The GPT gave me a simplified version of the code, leaving out some key functionality. I then asked it to write the code for those parts as well.
The code often returned to me in snippets, so I had to periodically ask for it to consolidate all the code into a single window. This interactive process took about 15 minutes to generate something I could test in Visual Studio. Had I coded this by myself, it likely would have taken me an hour or more. Click here to see a transcript of the entire GPT session.
Refining and Perfecting
Now, the GPT didn't get everything right. I had to update some method names and variable values in Visual Studio. All in all, I only had to change four or five lines of code out of more than 100 lines. Not bad!
Initial tests in Revit revealed some more quirks – specifically, a few rooms were reading the ceilings above, giving themselves seriously high ceiling heights. After more dialogue with my GPT and a few code tweaks, I had a functional and efficient add-in!
The Bigger Picture in AEC
Engaging with ChatGPT in this process underscores a key point: knowledge of coding and the Revit API is still crucial. Ultimately, I got a working add-in because I knew what the code should do and what questions to ask. Without that knowledge, it's unlikely I would have gotten anywhere. I liken it to an orchestra conductor – you must guide, fine-tune, and direct the AI to achieve the desired outcome.
Overall, the experience was empowering and insightful and offered a new perspective on problem-solving in our field. It provided a glimpse into the potential that AI tools like ChatGPT hold for the AEC industry. These tools are not just about doing the heavy lifting but enhancing our expertise, allowing us to tackle complex problems more creatively and efficiently.
Have you experimented with integrating AI tools into your workflow? The innovation potential is significant, whether it's for Revit add-ins or other applications. What uses have you found for the technology?
Sign up for ArchSmarter updates and get access to the ArchSmarter Toolbox, a collection of time-saving Revit macros, Dynamo scripts, and other resources. Plus you'll get weekly productivity tips, webinar invitations and more! Don't worry, your information will not be shared.
We hate SPAM. We will never sell your information, for any reason.