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

Updated: Jan 25

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.

GitHub - mcneel/pythonstubs: Python stubs for .NET assemblies

 

Where to


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

%appdata%\Roaming\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!

gif

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:

pyRevit/extensions/pyRevitDevTools.extension/pyRevitDev.tab/Developer Tools.panel/Generate API Stubs.pushbutton at master · eirannejad/pyRevit · GitHub


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'!!!


gif

Hope you enjoyied the post,

Cheers!



717 views0 comments

Recent Posts

See All