Error when using CPython in Revit 2020

Hi everyone :wave:

I’ve encountered a very weird problem with CPython.
I have two buttons created with pyRevit, Button1 and Button2.
Both buttons access another module that reads data from Revit extensible storage, the difference is that Button1 has #! python3 at the beginning of while Button2 doesn’t.

All these works perfectly fine in Revit 2022, but when I run Button1 in Revit 2020, it gives the error CPython Traceback: TypeError : No method matches given arguments for Get: (<class 'Autodesk.Revit.DB.ExtensibleStorage.Field'>, <class 'int'>) when running the following code:

if int(app.VersionNumber) >= 2021:
    unit = UnitTypeId.Custom
    unit = DisplayUnitType.DUT_CUSTOM
distance = entity.Get[float](self.dist_field, unit)

if I remove the #! python3 at the start of then this error won’t occur, but I need it for some other functions in Button1.

this post mentioned the same problem but didn’t have a solution…

Does anyone know how to solve this? Thank you!


i use this sometimes

rvt_year = int(app.VersionNumber)

# Get actual project units for length
if rvt_year > '2021':
    currentUnitLength2022 = Document.GetUnits(doc).GetFormatOptions(UnitType.UT_Length).DisplayUnits
    print ("rvt > 2021")
    print (rvt_year)
    print (currentUnitLength2022)

    currentUnitLength2021 = Document.GetUnits(doc).GetFormatOptions(SpecTypeId.Length).GetUnitTypeId()
    print ("rvt 2021")
    print (rvt_year)
    print (currentUnitLength2021)

maybe you can adapt that…

Hi @asasasa,
Unfortunately this is a bug of the current pythonnet version used by pyrevit. We’re working on updating it and finally bring some love to the cpython part of pyrevit, and it will be available in the next major release (pyrevit 5).

We can’t still give an ETA on this, but we’re getting closer…

1 Like

Hi @sanzoghenzo

do you think we have similar problem here? (or am I doing something that is normally supposed to work in IronPython but not in CPython?)

#! python3
#some imports and stuff
elem = doc.GetElement(list(selection)[0])
geom = elem.Geometry[impOptions]

throws this exception:

CPython Traceback:
AttributeError : 'FamilyInstance' object has no attribute 'Geometry'

I’m converting every script I wrote to python3 one by one. Do you think I should wait a bit more for pyRevit 5?

Yes, please.
Unfortunately CPython support was an half-baked feature that didn’t get the love it deserved.
The whole .NET8 transition is complicating things a bit, but we’re progressing bit by bit!
Stay tuned :wink:

Back to your error: are your sure that this worked on IronPython with that specific family instance?have you tried using elem.get_Geometry(impOptions) instead?

1 Like

ok…thanks for the confirmation :smiling_face_with_tear:

hi @sanzoghenzo

Yes, It works in IronPython. initially that code was working in IronPython just fine until I ruined everything. lol.
I actually tried get_Geometry but I, of course, forgot to change the square brackets to parentheses. Yeah, It seems to be working this way.
I’m definitely not an expert in programming but I find it fairly easier to use Python 3 compared to 2.7.7.
I will slow it down but will keep switching to CPython a bit more carefully. have lots of them on the way. Should I keep reporting the issues as I encounter them or should I just assume that you know them all already? if yes, then should I do it here or in GitHub?

thank you.

Since the main culprit is an outdated version of the pythonnet library, it’s not worth reporting the current issues, the are likely already fixed with the new version that we’re trying to use.
And my reaction would be the always same: “please wait for pyRevit 5” :wink: