Pyrevit intellisense

Hi i try to add intellisens to VS code (like in https://www.macro4bim.com/post/vscode-intellisense-for-revit )
I download all files and add to my python Intellisense:
image

settings.json:

{

    "workbench.colorTheme": "Default Dark+",

    "python.defaultInterpreterPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python39_64\\python.exe",

    "git.autofetch": true,

    "window.zoomLevel": 1,

    "python.autoComplete.extraPaths": [

   

    "C:\\Users\\pawel\\AppData\\Roaming\\pyRevit-Master\\pyrevitlib",

    "C:\\Users\\pawel\\AppData\\Roaming\\Visual Studio Setup\\Iron\\ironpython-stubs-master\\release\\stubs.min"

    ],

    "python.analysis.extraPaths": [

        "C:\\Users\\pawel\\AppData\\Roaming\\pyRevit-Master\\pyrevitlib"

    ]

}

Folders:


image
but autocomplete doesn’t work… Anyone use vs code to write scripts and have the autocomplete?
My vs code interpreter:
image
Thank you in adwance!

A little bit of dumb stuff going on… You probably have the pylance extension downloaded. To get it to work correctly I had to go the pylance extension, click on it’s settings and then change the setting for the folder (I didn’t try workspace, so that may work) and add the folders in there. Another thing I tried that worked was disabling the pylance extension, then it worked… just not as well as it would have.

Hopefully this helps!

1 Like

Thank you! Ok so i set my pylance extra paths:

and autocompleat works but i want to ask… It is “normal” that autodesk function don’t have info and nothing after “.”?
image
image

Pyrevit works better


Do you have an idea?

I have definitely not been paying attention to my emails…

One thing you can try is changing your import statement to be

from Autodesk.Revit import DB

and use DB.FilteredElementCollector() to see if that changes anything, this is also the “preferred” way to import rather than using *, as that can start clogging up what is in scope.

The other thing to try is run this script in pyrevit to generate new stubs. It looks like the stubs you have are structured differently than the ones I’m using, which may be causing some issues with the autocomplete. I believe I originally copied this code from the pyrevit dev extension if you prefer to find it there. This will also help with different versions of the API, you can generate the stubs per version and change the folders for whichever version you’re targeting/which version is giving you trouble.

"""Generate python stubs for this Revit version API."""
#pylint: disable=import-error,invalid-name,broad-except
__title__ = 'Generate\nAPI Stubs'
__context__ = 'zero-doc'

from pyrevit.coreutils import assmutils
from pyrevit import labs
from pyrevit import forms
from pyrevit import script


logger = script.get_logger()
output = script.get_output()


ASSMS = [
    'RevitAPI',
    'RevitAPIUI',
    # 'UIFramework',
    # 'Adwindows',
    'pyRevitLabs.Common',
    'pyRevitLabs.TargetApps.Revit',
    'pyRevitLabs.PyRevit',
]

dest_path = forms.pick_folder()

if dest_path:
    for assm_name in ASSMS:
        assm = assmutils.find_loaded_asm(assm_name)
        if assm:
            try:
                stubs_path = labs.PythonStubsBuilder.BuildAssemblyStubs(
                    assm[0].Location,
                    destPath=dest_path
                )
                print('Generated stubs for %s -> %s' % (assm_name, stubs_path))
            except Exception as sgEx:
                logger.error('Failed generating stubs for %s', assm_name)
1 Like

Thank you for your reply. I will look how it works.