top of page
Writer's picturemacro4bim

Create Python stubs đŸ±â€đŸ‘€

Updated: May 28

In a post of some time ago, I talked about the implementation of intelliSense and autocompletion of your Revit code using Visual Studio Code. VSCode intelliSense for Revit

As you can see from there, a side note is alerting you that, depending on the Revit version you are working on, the autocompletion could not be that accurate because the stubs might be not updates.


Well, this side note doesn't make me feel any fear anymore, because of a majestic program "hidden" in the pyRevit-Master repository, the pyrevit-stubsbuilder.exe!

With this, we can create python stubs for any Revit version!



During this post, I'll show you how I used it and what's the result. But first, Many thanks to Ehsan Iran-Nejad and Steve Baer at McNeel, creators of the opensource program.

 

Where to


Once installed pyRevit, you can find the application at the following path:

%appdata%\pyRevit-Master\bin

the name of the file is pyrevit-stubsbuilder.exe and, if you try running it, apparently nothing is happening.



How to


I'll guide you through the way I studied and ran this application. considering it is a .exe file and a prompt was visible for some milliseconds on my screen when I was running the app, I decided to run the program manually from the command prompt.

Of course, everything is easier if you run the command prompt directly from the directory containing the program.


Tip: You can do this by typing "cmd" on the windows search bar.


Once opened the program, you will also be albe to ask for help with the following command line:

pyrevit-stubsbuilder.exe -h

and here is the answer:

Usage:
    pystubsbuilder (-h | --help)
    pystubsbuilder (-V | --version)
    pystubsbuilder [--dest=<dest_path>] [--search=<search_path>...] <target_dll>...

Options:
    -h --help                   Show this help
    -V --version                Show version
    --dest=<dest_path>          Path to save the subs to
    --search=<search_path>      Path to search for referenced assemblies

There is not very much to add, right? Maybe just a couple of clarifications around the <target_dll>, that is the golden RevitAPI.dll and the --search which is to use in case the dll is referencing other dlls, the tool will look into the search folders to find them.


Just for completion, let me run live a test creating some Revit 2020 stubs on a new folder just created on my desktop. Here is how it looks:

pyrevit-stubsbuilder.exe --dest="C:\Users\giuse\OneDrive\Desktop\New folder" "C:\Program Files\Autodesk\Revit 2020\RevitAPI.dll"

target path is C:\Users\giuse\OneDrive\Desktop\New folder
building stubs for C:\Program Files\Autodesk\Revit 2020\RevitAPI.dll
stubs saved to C:\Users\giuse\OneDrive\Desktop\New folder\Autodesk

 

AND NOW WE HAVE THE STUBS

Fast and silent, like a ninja!


Just for completion, this, for me, was the path to add to the extra-path for the autocompletion:

"C:\\Users\\giuse\\AppData\\Roaming\\py_stubs\\Autodesk\\Revit"




That said...

The method above quoted is the one I used once discovered the application but not the only one.

For those of you that prefer to have a life a bit easier, taking advantage of some masters works... here it goes:


This is a pyRevit pushbutton that does exactly what is said above, for the Revit version in use.


 

I've nothing else to say than SPLENDID... or, well, that old but gold SMOKIN'!!!



Hope you enjoyied the post,

Cheers!



1,974 views5 comments

Recent Posts

See All

5 comentarios


Jean-Marc Couffin
Jean-Marc Couffin
28 may

also in CMD you don't need to indicate the exe extension to call programs, neither the help flag if you are not providing any argument


from pyrevit-stubsbuilder.exe -h to pyrevit-stubsbuilder

Me gusta
macro4bim
macro4bim
28 may
Contestando a

Correct, the "-h" is indeed only to ask for help. I also pasted what the response should be, so to make everyone comfortable with the line of code suggested afterwards. While for the ".exe", I actually didn't know, Thanks Jean-Marc, as always!! :)

Me gusta

Jean-Marc Couffin
Jean-Marc Couffin
28 may

%appdata% defaults to the roaming folder

you need to edit the path from %appdata%\Roaming\pyRevit-Master\bin to %appdata%\pyRevit-Master\bin

Me gusta
macro4bim
macro4bim
28 may
Contestando a

Actually is not even entirely correct because saying %appdata%\pyRevit-Master\bin"" assumes that the user does not have a custom installation of the pyrevit core... Maybe is the time for another blog post to clarify this aspect as well :)

Me gusta
bottom of page