LearnRevitAPI
Feb 5, 2023
Chat GPT for developers
🤖 Advances in AI technology in the last couple years have changed the way we will work forever. And while many have fears that it might replace us in the near future, I think of it as a tool that can help us be more efficient with our work.
💬 Chat GPT has shocked the world with its capabilities, and over time we will see even more shocking tools coming out. I think that Google will release its own AI very soon, and I would not be surprised if it's even crazier than Chat GPT. Let’s wait and see how the tech giant can surprise us
Chat GPT for Revit API Developers
💪 There is no doubt that Chat GPT is an amazing tool for all. But Let’s look how it can help us write our python code with Revit API.
✅ Chat GPT can help developers with a lot of tasks, such as referencing Revit API documentation, translating C# code to Python, writing functions, asking for code explanations, debugging, and adding documentation to the code and I am sure there are more ways it can be helpful.
❌ While it can produce amazing answers, I experienced that quite often it will suggest me to use something that does not exist in Revit API or it has some bugs in the code. And it does it with a confidence. Nevertheless, it’s still great to get a piece of code that we can try to fix and sometimes it saves us time and other times it can't produce results good enought.
🚸 Lastly, I think it’s a great learning resource for beginners. Not only it can produce some code, it can also break it down and teach us what’s necessary to understand it. So you get an AI tutor that can teach you 1on1. But as a beginner you might not notice incorrect answers and it might be an issue.
Let’s look at it in more details
Reference Revit API Docs
✅ It’s worth asking chat GPT a question related to Revit API documentation. Often times it will find the right classes and methods and give you some code examples. This can save us time and allow us to quickly find what we need.
❌ However, since Revit API is very niche topic, chat GPT is often not able to produce the right answers. And the worst part is that it will make up names of Properties and Methods which do not exist in Revit API, so be aware of that when you test its code. Let's try it.
⌨️ Chat GPT prompt:
How to create a Filled Region in Revit with python and Revit API? Provide syntax for pyRevit
❌ This generated code is not valid for too many reasons.
- Dynamo syntax
- Missing Transaction
- It's made up some methods
- It doesn't even try to create any shape for the region...
Let's give it another chance.
⌨️ Chat GPT prompt:
How to create FilledRegion with Revit API and python? I want to create a simple square filled region, preferably use example from Revit API documentation.
🔎 The result seems to be much better. At least it tried to make a CurveLoop but it still has many issues. Maybe if we chat a little more it would understand all the issues and correct them, or maybe not.
👇 I am going to leave my snippet which actually creates a FilledRegion for comparison.
Translate C# to Python
💻 As Revit API developers we often have to deal with C# examples. And while translating C# to Python is not so complicated, you need to know a little bit about C# to read code correctly. And on large snippets it can become time consuming.
🍀 Luckily, Chat GPT can help us out.
We can ask it to translate snippets from C# to Python and often times you will get good results.
❌ I’ve noticed that sometimes it has obvious bugs or something is not exactly right. But it’s much quicker to fix it than starting from scratch. Especially for beginners!
⌨️ Chat GPT prompt:
Can you translate C# RevitAPI snippet to python?
```code here```
C# Snippet
Chat GPT translation
✅ The translation is good.
It has a minor bug while getting doc and uidoc. But the rest works fine.
* It should use __revit__ instead of revit.
Write Functions
😴 I am lazy. And I am always on a lookout to be more efficient. So sometimes even if I know how to write a function that I need, I will ask chat GPT to write it. Then I can correct a few things to my liking and it saves me time.
👇 For example:
⌨️ Chat GPT prompt:
Write me a python 2.7 function to get today's date with the following format:
5, February, 2023 (12:30)?
✅ This is a valid function and it returns exactly what we need.
You will be able to create a lot of simple functions, especially when it's about python and not Revit API!
Explain the given code
🐣 As a beginner you will struggle to read other people’s code. Especially if it’s not documented one. But you can ask chat GPT to break it down for you and explain parts that you do not understand.
🔎 Take some code and ask chat GPT what it does. Then if something is still not right, ask for explanation. And after a few messages back and forth you might learn how to write it yourself.
📑 You can push it further and just ask it to teach you something about programming. It won’t always be good, but I think it will be able to explain a lot of things that beginners struggle with.
Debugging
🐛All programmers encounter bugs. But beginners will encounter them even more. Also they are not so quick at debugging, because every error message is new to them.
🤖 So chat GPT might be able to help you debug some code. It should be able to fix a lot of bugs, but don’t expect it to solve complex tasks, where solution is not so straight forward. Just give it your code, provide Error message and hope that it will be able to fix it somehow.
Add documentation to the code
📝 Lastly, I want to remind you that it’s important to document and type hint your code. Not just for others, but also for you in the future and you IDE.
👀 By adding explanation and type hinting to your code you will improve readability of your code. And this will lead to a more maintainable code and easier access of reusable snippets.
⌨️ Chat GPT prompt:
Can you document my code and add type hinting for arguments.
{code}
How do you use it?
🙋♂️ If you use Chat GPT feel free to share your observations and the most useful prompts. I would love to hear how Chat GPT can help us even more in our coding sessions.
Join Newsletter
📩 You will be added to Revit API Newsletter
Join Us!
which is already read by 7400+ people!
◼️BLACK FRIDAY DEAL 20% OFF. Ends in: