Revit API Autocomplete in pyCharm

Let's finish setting up our Dev Environment for Revit API. Revit API will help you a lot when you code, so it's quite important to add it early on.

Revit API Autocomplete in pyCharm

Let's finish setting up our Dev Environment for Revit API. Revit API will help you a lot when you code, so it's quite important to add it early on.

Summary

Why we need Revit API Autocomplete?

As a beginner you won't be familiar with Revit API, and adding autocomplete can solve a lot of issues before hand. Also it's not as complicated, we just need to configure our IDE(text editor for programmers) by providing files called stubs.

Install Python

Let’s start with installing Python.

It does not matter which python version you are going to use because we are not going to run Revit API scripts from pyCharm. We use it for comfort while we write our code. All code will be executed via pyRevit, RevitPythonShell or Dynamo Python Nodes.

I will install python 2.7.18 because it seems to never give me issues when I create my environment. Many people have reached out to me that they experienced some issues when they try to create virtual environment in pyCharm with certain python versions. If that’s the case for you, try installing another python version and see if that works, but I would recommend to start with python 2.7.18.

Install pyCharm

First of all install pyCharm.

🎦 You will see how I do that in the video, and it's not complicated.
I would recommend to tick all the tick boxes in this part of installation👇

Create Virtual Environment

Once you have your pyCharm installed we need to create a new Virtual Environment for our project.

Virtual Environment allows us to preconfigure python environment for different purposes. Imagine you have a container that you would use for Revit API development. You will put all necessary stuff like packages, references and stubs for autocomplete. And you will use this container when you work with Revit API.

🎦Follow the video to create your virtual environment.

Once you create your virtual environment test your regular python autocomplete. Try to write something simple and you should see pyCharm autosuggesting methods for you. Also it takes some time if you just create virtual environment, so don't get scared if you won't see it right away!

👇Example to test python Autocomplete.

import os
os.path.join # This should give autosuggestions 
Add Revit API stubs

By now you should have your pyCharm virtual environment. And basic python code gives you autocomplete suggestions. Now we can look at how we could add Revit API Autocomplete.

First all of we need to get Revit API stubs. Check out the link below in Downloads section. Unzip the file and place it somewhere secure on your computer.

Then we need to add Reference to the right Revit API folder in Virtual Environment references.

🎦See the video to learn how it's done

Once you make your Revit API autocomplete work, do the same thing for pyRevit library. We will often use certain modules from there, so it's good to have autocomplete for it as well.

Usually pyRevit masters folder is placed in App Data folder. Use the syntax below to find it. If you can't find it there, you will need to figure out where it got installed. I saw it being installed in C: drive once, so you might have a look there as well.

%appdata%\pyRevit-Master\pyrevitlib
Conclusion

If you followed the video you should have your Revit API Autocomplete working. It will provide a lot of help once we start coding.

P.S.

We can create multiple virtual environments for different Revit API versions, but I have used single Revit API stubs version for years. You won't have autocomplete for updated or new classes, but we can type them manually.

💡 You will learn how to find changes in Revit API docs in one of the next videos.

⌨️ Happy Coding!

HomeWork

pyCharm Autocomplete will speed up and help you write Revit API scripts. I highly recommend setting it up before moving to the next lessons.

✅ Download pyCharm
✅ Setup Revit API Autocomplete

❓ Ask in Discord if you need help.

⌨️ Happy Coding!

Questions:

Why I get an error when I run Revit API script in pyCharm?

Why I get an error when I run Revit API script in pyCharm?

How to get other Revit API stub versions?

How to get other Revit API stub versions?