IntelliSense for Python

Is it possible to enable IntelliSense of functions, for a custom python module, inside Dynamo’s Python node editor?

I can import this custom module, without issues. Here is how module file SomeModule.py looks like:

import math

class SomeClass:
    
    @staticmethod
    def Addition(n1,n2):
        return n1+n2
    
    @staticmethod
    def Subtract(n1,n2):
        return n1-n2

like so:

path = r'C:\dynamo\SomeModule'  # SomeModule.py file is inside this folder
sys.path.append(path)

from SomeModule import SomeClass
OUT = SomeClass.Addition(2,3)

The upper code works with or without empty 'init.py file in the folder ‘C:\dynamo\SomeModule’.

However, IntelliSense of functions ‘Addition’ or ‘Subtract’ does not work.

I even tried referencing a custom C# library, instead of python module. Here is the source code:

using System;

namespace SomeNamespace
{
	public class SomeModule
	{
		public static int Addition(int n1, int n2)
		{
			int n3;
			n3 = n1 + n2;
			return n3;
		}
		
		public static int Subtract(int n1, int n2)
		{
			int n3;
			n3 = n1 - n2;
			return n3;
		}
	}
}

When source code compiled, it can be referenced in Python node without issues as:

import clr
clr.AddReferenceToFileAndPath(r'C:\dynamo\SomeModule\SomeLibrary.dll')
from SomeNamespace import SomeModule

OUT = SomeModule.Addition(2,3)

But again, autocomplete does not work.
Which is strange, because when ‘ProtoGeometry.dll’ library is referenced, IntelliSense works:

Does anyone know how to enable IntelliSense for a custom python module, or C# dll library?

I am aware of Talarico’s stubs for different editors (Atom, PyCharm, VSC…), but I would like to use Dynamo’s native Python editor, not an external one.

I would be grateful for any kind of help

Here are both the .py and .dll files.

1 Like

@Aaron_Tang
@Aparajit_Pratap ,
@Michael_Kirschner2
@Michael_Dewberry1
@Dimitar_Venkov
@solamour

Do you have any suggestion on how to enable autocomplete inside Dynamo Python node, for a custom python module, or for a compiled C# .dll?

How does ProtoGeometry.dll do it?

I would be grateful for any kind of reply. Thank you in advance.

Hello @george it should do it by default, as with my silly Python module example below:

3 Likes

Thank you very much @solamour !

I just tried your module (replicated everything from module content to its location, to the code to call in the Python node).

Still, I can’t get intellisense to work. The methods inside the Student class work without issues, just the intellisense does not work.

This is with Revit 2019.2:
image

This is with Revit 2022:

Neither worked.
I also tried switching to CPython3 on Revit 2022, but again intellisense didn’t show up.

Interestingly on both Revit 2019 and 2022, the classes inside the ‘Autodesk.DesignScript.Geometry’ namespace (like: ‘Line’, ‘Point’…), appear with intellisense without issues.

So I am wondering if maybe I would be more successful with C# dll? Do you have idea, why the upper C# library does not “support” intellisense?

  • for custom Python modules (under CPython3 engine) it seems that it is necessary to run the script at least once
  • ditto for dll assemblies with the CPython3 engine (need to run it for the first time).
  • with IronPython it seems to work fine without running the script before (for dll assemblies)

test import 2 autocompletion py

5 Likes

@george our development team took a look and there is definitely something weird going on here, so we’ve filed a task to investigate :slight_smile:

5 Likes

Hello @george
As @c.poupin mentioned above:
Please try to run the script once (with all imports) then autocomplete should work
In your first example, just try to run the following code then try autocomplete

path = r'C:\dynamo\SomeModule'  # SomeModule.py file is inside this folder
sys.path.append(path)

from SomeModule import SomeClass

Another issue that might affect autocomplete is that CPython sometimes caches the imported modules so contents might be stale. In this case you can use the button under Dynamo->Preferences->Features->Python => Reset CPython

5 Likes

Thank you very much for the effort, all of you! @c.poupin @tiberiu.pinzariu @solamour !!!

I can’t get it to work. Neither on Revit 2019.2, nor on 2022.
I tried as you suggested: importing the python module first, saving, and closing the Python node. ‘Run’ the Dynamo. Then opening the Dynamo node again, and checking if intellisense works.

I made a video with Revit 2022 and its Dynamo 2.10.

I tried both IronPython and CPython. Intellisense didn’t work on either of them.

Interestingly the methods from the custom python module, work without any issues (I show it in the vide). But instellisense does not.

1 Like

@george It does look like there are issues with autocomplete/Intellisense for types imported from external python modules. It does not work for Dynamo 2.12 or lower versions.
Since Dynamo2.13 it works only with the CPython engine and only if you execute the import code first.

However I am still puzzled about the autocomplete issues you noticed with c# libraries. I just tried Dynamo2.10 Sandbox and autocomplete worked as expected (with you example code).

Could you create a clip with using the C# library? I would like to confirm if that is broken too…
Maybe try to reproduce the issue using DynamoSandbox.exe (not from Revit)
Can you also try to put the c# library in the Dynamo folder (next to ProtoGeometry.dll) and try to import it with clr.AddReference(‘SomeLibrary’) ?

3 Likes

Hi @tiberiu.pinzariu ,

According to what @c.poupin showed:

I just tried on:

  • Revit 2019 (Dynamo 2.0.2.68) - intellisense of the custom C# library didn’t work.

  • On DynamoSandbox.exe (same version 2.0.2.68) intellisense didn’t work either.

  • On Revit 2022 (Dynamo 2.10), with ‘IronPython2’ engine, the intellisense worked!
    Interestingly, the docstrings are not appearing:

image

I added the following comment to the custom C# library methods in the mean time, and I was expecting that these comments would show up together with intellisense.
That would be my second question/topic, once intellisense for custom python module is solved.

using System;

namespace SomeNamespace
{
	public class SomeModule
	{
		/// <summary>
		/// This is a comment for Addition method
		/// </summary>
		public static int Addition(int n1, int n2)
		{
			int n3;
			n3 = n1 + n2;
			return n3;
		}
		
		/// <summary>
		/// This is a comment for Subtract method
		/// </summary>
		public static int Subtract(int n1, int n2)
		{
			int n3;
			n3 = n1 - n2;
			return n3;
		}
	}
}
  • On Revit 2022 (Dynamo 2.10), with ‘CPython3’ engine, an error is raised on line:
clr.AddReferenceToFileAndPath(r'C:\dynamo\SomeModule\SomeLibrary.dll')

I didn’t know PythonNET does not have clr.AddReferenceToFileAndPath method, when I replace it with:

clr.AddReference(r'C:\dynamo\SomeModule\SomeLibrary.dll')

the intellisense didn’t work with the following message in the Dynamo console:

Failed to load module: SomeModule, with statement: from SomeNamespace import *
Failed to load module: SomeModule, with statement: from SomeNamespace import *

1 Like

@george
Thanks for the great info. Great to hear that you got IronPython intellisense working on Dynamo 2.10.
Regarding docstrings:
I do not think docstrings for custom types ever worked inside dynamo’s python editor. We will definitely log this issue.

For PythonNET intellisense please try it without the extension in the name.
Step1: Add the binary SomeLibrary.dll in the Dynamo install folder (next to ProtoGeometry.dll)
Step2: Import it like so:

import clr
clr.AddReference('SomeLibrary')
from SomeNamespace import SomeModule

Step3: Run it first.
Step4: Try intellisense on the SomeModule type
Note: There might be a way to load the SomeLibrary from a different path by using sys.path.append(‘path to SomeLibrary.dll’) + clr.AddReferenceToFile(‘SomeLibrary’)

1 Like

Thank you @tiberiu.pinzariu.
It worked perfectly on Revit 2022, CPython engine, Dynamo 2.10.1.
I went directly with your advice in the last sentence (so didn’t copy the ‘SomeLibrary.dll’ to the folder 'ProtoGeometry.dll` folder). With your advice, the intellisense worked:

# Load the Python Standard and DesignScript Libraries
import clr
import sys
sys.path.append(r'C:\dynamo\SomeModule')

clr.AddReference('SomeLibrary')
from SomeNamespace import SomeModule

SomeModule  # typing '.' activates intellisense

But now I have a different issue :slight_smile: I will post it in a new reply.

1 Like

Hi @tiberiu.pinzariu
I would like to thank you for all the help in testing and for all the useful advises.
@solamour thank you for raising this issue with the Dynamo team.
@c.poupin as always your programming problem skills are impeccable. Thank you for solving this as well.

2 Likes