Add .dll reference to get the Intellisense


#42

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


#43

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!


#44

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.


#45

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


#46

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

#47

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.


#49

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


#50

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!


#53

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.


#54

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/


#55

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


#56

Thanks Thomas and erfajo