pyRevit vs C# - types and autocompletion

Hi
As we all know python is quite a flexible coding language.
You can choose to either specify your types or not.

My problem is that because ‘iron python’ (the platform in which our python code runs in) does not support types - I am forced to not declare types in any of my functions.

By not declaring the variable type, its type is ‘Any’ by default, which leads to no auto completion, which sucks so bad.

In this simple example, upon writing the function - the IDE wont suggest me any of the Element class properties or methods, simply because it doesn’t know that element is necessarily of type Element:

def print_element(element):
        print(element.Id)
        print(element.Name)

But if I could declare it like so, my life can be so much easier:

def print_element(element: Element):
    ....

What do you guys do to overcome it?
Maybe its specific to older versions? I am using Revit 2021

Anyone please?
I still didnt find an answer for this…

Not sure what IDE you are using but maybe this is what you need?
no autocomplete for pyrevit, but you will get for Autodesk.Revit.DB

Do you know C# already? You can always use VS or VS Code and skip the python entirely. Either compile a DLL and invoke with a pushbutton, or create a script.cs and just copy the external command into that file in the button folder.

Thanks but this is not what I meant.
I think that what I’m referring is called ‘Type Hinting’, specifically for custom functions that I wrote.

Going back to the simple example of the original post, when I write a function and declare which variables the function takes, I cannot declare the variable types and therefore I will not get suggestions from my IDE for that variable within the function’s scope, for example Name, Id upon typing element.

This is because the IDE does not know that the variable is necessarily of type Element.

Or in other words - is there a workaround the fact that IronPython does not support python types?

Yep. C#.

Type hints are python 3.5+

the stubs will give you access to Autodesk.Revit.DB (which includes Element) so you get limited support for properties and methods…

1 Like

So I guess Ill learn how to use C# :man_shrugging:
I did notice that unlike pyRevit, with C# I have to rebuild my code and restart Revir for every change I make to the code… well this is annoying.

Replace script.py with script.cs. But i was assuming that you already knew c# based on the thread name comparing Python to it. The majority of pyrevit users likely don’t know c# and get by fine using Code or pyCharm with the stubs for completion.

I use notepad++ since I love punishing myself

1 Like

:rofl:

Definitely love being punished