Add .dll reference to get the Intellisense

It was tested on Community Edition. Bear in mind that this is not ideal. I would give it a try, but .NET libraries are notoriously not well integrated with Python so this might be a superficial fix/help.

1 Like

Hi all, thanks for all the info on this, but for some reason it’s not working for me and I have no idea why:

For vscode I have already:

  • Installed python extension
  • Download ironpython stubs (made sure files were unblocked)
  • Amended settings as per @Gui_Talarico’s settings

I’m not sure why the intellisense isn’t working, I know this has already been discussed, but if anyone can spot something I’ve done wrong I really would appreciate it:

{
"python.linting.pylintEnabled": false,
"python.linting.enabled": false,
"python.linting.pep8Enabled": false,
"python.pythonPath": "C:\\Program Files\\Anaconda3\\python.exe",
///"python.pythonPath": "C:\\Program Files (x86)\\Python\\Python36-32\\python.exe",
"python.autoComplete.extraPaths": [
    "C:\\Users\tpovey\\.vscode\\ironpython-stubs-master\\stubs.min"],
"python.autoComplete.preloadModules": [
    "Autodesk.Revit.DB",
    "Autodesk.Revit.UI"
]

}

Cheers,

TJ

Hi @Tom_James

Copy Python2.7 to C:\Python27 folder location and download the ironpython stubs in C:\Test folder. Finally Copy these settings in the VSC:

{
"python.linting.pylintEnabled": false,
"python.linting.pep8Enabled": false,
"python.pythonPath": "C:\\Python27\\python.exe",
"python.autoComplete.extraPaths": [
    "C:\\Test\\stubs.min",
    "C:\\Test\\revitpythonwrapper.min"
    ]
}

Here is the process in action:

4 Likes

Thanks @Kulkul you’re a star, not sure why it worked as I just moved everything from the paths above directly to my C drive. Too long a path maybe?

Works anyway, thanks very much,

TJ

Hi guys.
I was trying Konrad’s tutorial on how to get the autocomplete in pycharm and, I was just wondering what you guys mean by stubs?
What is it exactly that I should copy into the folder and where do I get it? I get the feeling that it’s not the DLLs themselves since the stubs folder doesn’t contain any DLLs.

I have struggled to create Python Code for Dynamo Nodes using the RevitAPI with Visual Studio Community 2015 and Sublime, but it seems it works now with Visual Studio Code. So I have created 2 small tutorials:

How to install Visual Studio Code to Create Python Code with Autocomplete/Intellisense [including the RevitAPI.dll]:

  1. download the stubs from https://github.com/gtalarico/ironpython-stubs :

  1. unblock the zip file after download:
    a) right click on the zip file, properties:
    2
    b) unblock the file:

  2. extract to a folder of your choice on your computer (eg. with WinRar) - recommend is into C:\Test:

  3. Install Python 2.7.14 64bit (recommend to the path C:\Python27): https://www.python.org/downloads/windows/ https://www.python.org/ftp/python/2.7.14/python-2.7.14.amd64.msi

[info: Dynamo us using IronPython, but it seems that IronPython is not supporting the Autocomplete function, because of this we use Python2.7.14 to create the Python Code we use later in the Python Node in Dynamo]

  1. Install the software Visual Studio Code: https://code.visualstudio.com/download
    [further details to Visual Studio Code: https://code.visualstudio.com/docs/languages/python & https://code.visualstudio.com/docs/python/settings-reference ]

  2. Open Visual Studio Code and install these Extensions by using the search bar at the top (Erweiterungen [in german]) :
    [further details: https://github.com/Microsoft/vscode-python ]
    5

  3. To open the user settings use the keyboard combination CTRL + , [in german: STRG + ,]
    Add the following lines to the user settings and adjust the path to your stubs.min folder and your python.exe file:

    {
    “python.linting.enabled”: false,
    “python.linting.pep8Enabled”: false,
    “python.autoComplete.preloadModules”: [
    “Autodesk.Revit.DB”,
    “Autodesk.Revit.UI”
    ],
    “python.pythonPath”: “C:\Python27\python.exe”,
    “python.autoComplete.extraPaths”: [“C:\Test\ironpython-stubs\release\stubs.min”],
    }

  1. Save your settings and restart Visual Studio Code

*How to explore .dll libraries in Microsoft Visual Studio Community 2015:

[The result of this is similar to revitAPIdocs.com to explore the Revit API, but offline]

Install Microsoft Visual Studio Community Edition 2015… (not further described in this tutorial, use google)

Open the object browser in Visual Studio Community ( Menu: View -> Object Browser )

7a

Create a Custom Component Set:

7

Add the dll libraries you want to explore:

8

for example you can add to the object browser:

• ProtoGeometry.dll ( C:\Program Files\Dynamo\Dynamo Core\1.3\ProtoGeometry.dll )
• DynamoServices.dll ( C:\Program Files\Dynamo\Dynamo Core\1.3\DynamoServices.dll )
• RevitNodes.dll ( C:\Program Files\Dynamo\Dynamo Revit\1.3\Revit_2018\RevitNodes.dll )
• RevitAPI.dll ( C:\Program Files\Autodesk\Revit 2018\RevitAPI.dll )
• RevitServices.dll ( C:\Program Files\Dynamo\Dynamo Revit\1.3\Revit_2018\RevitServices.dll )
• DynamoRevitDS.dll ( C:\Program Files\Dynamo\Dynamo Revit\1.3\Revit_2018\DynamoRevitDS.dll )

6 Likes

Hi,
is the setting compatible with the python 3.6? I did the steps in vscode but I get some errors. I don’t know if it is for the python version I am currently using(v3.6).

thankyou, that was helpful. Do you get the same errors in problem panel in the vs code? I saw some videos. none of them had these errors.

Got the answer from @gtalarico. I had to disasble the linter

I found this solution:

  1. Copy the folders (DSCore, Autodesk, Revit and RevitServices) from ironpython-stubs-master\release\stubs.min and paste in C:\Program Files (x86)\IronPython 2.7\Lib\site-packages

  2. Open Visual Studio and create a new IronPython Application, go to Tools > Python Tools > Python Enviroments.

  3. In the Python Enviroments window search IronPython, go to Intellisense and click on the RefreshDB button.

7 Likes

I have downloaded the latest version of Visual Studio Code (1.30.2). And it seems, that "python.autoComplete.preloadModules" is deprecated. It seems I have to use now

"python.jediEnabled": false

to have a fast IntelliSense, because it enables a new language server.

{
"python.linting.enabled": true,
"python.linting.pep8Enabled": true,
"python.jediEnabled": false,
//"python.autoComplete.preloadModules": [
//    "Autodesk.Revit.DB",
//    "Autodesk.Revit.UI"
//],
"python.pythonPath": "C:\\Python27\\python.exe",
"python.autoComplete.extraPaths": [
"C:\\stubs.min"
],
"python.linting.pylintEnabled": true,
}

It seem like for Rhino there is a good auto complete solution for IronPython:

But I don’t know this can be used somehow for Dynamo Iron Python stuff ?

@Gui_Talarico @erfajo

Hi, does this mean that you can use a later version of python (ie 3.6 or 3.7) that doesn’t rely on “python.autoComplete.preloadModules” or still only use the .net Python flavour IronPython 2.7.3? I’ve found a way to use this in visual studio community but would like to configure this in VS code too.

1 Like

python 3 is not compatible. You should use IronPython. And if you use Python 2.7.x you should be aware of that some parts like numPy are not working. I have created a small tutorial for my customers, it is in german but I think with an translator u can follow: https://www.enjoybim.de/2019/01/18/mit-intellisense-dynamobim-custom-nodes-erstellen/

Thanks Thomas and erfajo

Any updates for Visual Studio Code 2022? I am getting some of th elibraries, but only some the first levels of autocomplete.

Auto-complete for Designscript should have you make a choise for Package method in a dropdown. :slight_smile:

This seems to be mostly working(Revit Python in Visual Studio Revit Stubs 2022 for Python Revit Intellisense) Still missing a few elements:

September 01, 2022

Coding in python and fighting the #Autodesk Python basic editor with all the Case Sensitive syntax I decided to use Visual studio to code/debug. Problem is I was missing stubs. Grabbed them from the gtalarico GIT iron python stubs through a Visual studio Community 20220 CLONE in Visual Studio Community 2002:

Adding the references to Visual studio:

Tools>Options and:

Add Stubs Path to the top-level folder containing stubs(4) along with the Autodesk revit generated Stubs(5) and some GIT HUB Cloned Iron Python Stubs(6) and the general iron python stubs (7)(see below):

STUBS PATH:

C:\Users\rallen\source\repos\ironpython-stubs\release\stubs

SEARCH PATHS:

C:\Users\rallen\source\repos\ironpython-stubs\release\stubs\Autodesk

C:\Users\rallen\source\repos\ironpython-stubs\release\stubs\DSCore

C:\Users\rallen\source\repos\ironpython-stubs\release\stubs\IronPython

C:\Users\rallen\source\repos\ironpython-stubs\release\stubs\Revit

C:\Users\rallen\source\repos\ironpython-stubs\release\stubs\RevitServices

NOTE:

%userprofile% didn’t appear to work in the settings an the Semicolon “;” was easiest to separate the values. Next check the semicolons were changed to linefeed/breaks for readability by Visual Studio Community 2022.

3 Likes

@Marcel_Rijsmus Is this what you meant? I am Adding references to see if they bleed through into the python editor

…
No change:
image

No, no no, i want to have bleeding through to DS.
Have it say Revit.Element.SelectorBy,Id (Id, true)
or %packageName%Element.Selector.ById)
so no ambiguous… errors anymore if you use DS, instead have a dropdown to choose which method.
Choose your namespace, so to say, a Wishlist item, i guess

@Marcel_Rijsmus completely agree. We need edits that expose the methods and constants.