Add .dll reference to get the Intellisense

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

@Tom_James
The problem is not the stubs files, mine are located [ “user”\.vscode\stubs.min ] and mine works perfectly.
The python installation is problem. Placing that somewhere else than what is suggested will give you trouble. I did the exact same mistake initially :slight_smile:
Meaning “python.pythonPath”: “C:\Python27\python.exe” is mandatory somehow if you dont want to do a lot of editing :slight_smile:
By the way, dont use Python 3.6 since it is syntactically different than Python 2.7
AND install x64 bit version!

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.

you can find the stubs here

as written by @Konrad_K_Sobon in this post

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).

You cannot use Python 3.6 (and neither Python 2.7)
You can only use the .net Python flavor IronPython 2.7.3, which in syntax is similar to Python 2.7 versions, but be careful, you cannot use numpy!

1 Like

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

Linter is not that bad, but yes you need to know that the scripting you do inside dynamo is wrapped. This means that you will have to accept certain errors. I also verify my code against the pep8 standard (http://pep8online.com) again with acceptance of some errors.

This is how I initiate a script file. First I set the sys path, next I load Python modules, and then .Net modules. Hereafter comes the CLR modules (Common Language Runtime). Finally, before the code, I load the needed Revit and dynamo modules.

This will give a pep8 error because the sys.path needs to be set before loading Python modules and CLR needs to add references before you can add Revit and dynamo modules. But it is organized better than mixing references and imports, which I widely used in the community.

The below is just a sample fetch from different scripts just to show the syntax I use. If you are interested, then try to see the DanEDU package for how to build an OOP environment.

# coding=utf-8
# This file is covered by the LICENSE in this dynamo package 'extra' folder
'''
description
'''

# Set sys.path
import sys
sys.path.insert(0, 'C:\Program files (x86)\IronPython 2.7\Lib')

# Python module
import traceback

# .Net module
import System

# Common Language Runtime module
import clr
clr.AddReference('ProtoGeometry')
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
clr.AddReference('RevitNodes')

# Revit and Dynamo module
from Autodesk.Revit.DB import Category, BuiltInCategory, FilteredElementCollector
from RevitServices.Persistence import DocumentManager

# argument assigned the IN port
docs = IN[0]

# core data processing
do something...

# return assigned the OUT port
OUT = docs

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

you dont need “python.autoComplete.preloadModules”, the “python.autoComplete.extraPaths” loading the stubs files are taking care of this.

I am afraid it was me who first time made the error of not removing the lines I had commented out. So It might be my fault that this "error" (with “python.autoComplete.preloadModules”) keeps popping up. sorry for that :slight_smile:

It could also be @Gui_Talarico since I know we discussed this issue long time ago and I followed some of his guidelines. I simply can’t remember how or why these lines ended up in the recommendation for the setting file for VSC.

One thing for sure… It is an enormous contribution by @Gui_Talarico that he has created those stubs files and maintain them!

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/

…and it is IronPython 2.7.3 …at the moment :slight_smile:

Thanks Thomas and erfajo

you have any document can add stub in pyCharm ? Thanks you !