CPython method overloading problems (Dynamo 2.10 & Python3)

Hi folks,

I’m having trouble using method overloading when using the CPython engine in Dynamo 2.10
Please check the following code to create a schema and place an instance of it in an element in the model.
It works just fine in IronPython but crashes in CPython (I skip the import block for brevity):

component = UnwrapElement(IN[0])

TransactionManager.Instance.EnsureInTransaction(doc)

def create_schema():
    schema_guid = System.Guid("DF3BBCC1-4D4D-4A01-B444-F9722814F9CE")
    schema_builder = SchemaBuilder(schema_guid)
    schema_builder.SetReadAccessLevel(AccessLevel.Public)
    schema_builder.SetWriteAccessLevel(AccessLevel.Public)
    schema_builder.SetSchemaName("TestSchema")
    schema_builder.SetDocumentation("Test schema to store ids")
    field_builder = schema_builder.AddSimpleField("ParentComponentID", System.String)
    schema = schema_builder.Finish()
    return schema

def add_schema_instance(schema, rvt_element):
    field = schema.GetField("ParentComponentID")
    schema_instance = Entity(schema)
    schema_instance.Set[System.String](field, "ID0004")
    rvt_element.SetEntity(schema_instance)
    

TransactionManager.Instance.TransactionTaskDone()

schema = create_schema()

When I try to port it to CPython, this same code crashes with exception

Warning: TypeError : No method matches given arguments for Set: (<class ‘Autodesk.Revit.DB.ExtensibleStorage.Field’>, <class ‘str’>)

I have tried different permutations and no overloading like

schema_instance.Set(field, "ID0004")

But nothing seems to work…

What is the new syntax for method overloading when using CPython with Dynamo?

Thanks in advance and happy 2022 everyone!

I think you are trying to call a method with two parameters? I think your overload type list needs to include both types, the field and the string.
It’s also quite possible the overloading in pythonNet is just broken - I believe the approach has changed in the latest versions.

currently, it looks like PythonNet doesn’t work with template Parameter

Thanks guys, I’ll stick to IronPython in the meantime

Any new of this? I have the same problem using the class “IFamilyLoadOptions”.

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit import DB
from Autodesk.Revit.DB.Structure import *


class FamilyLoaderOptionsHandler(DB.IFamilyLoadOptions):

    def OnFamilyFound(self, familyInUse, overwriteParameterValues):
        overwriteParameterValues = True
        return True

    def OnSharedFamilyFound(self, sharedFamily, familyInUse, source, overwriteParameterValues):
        source = DB.FamilySource.Family
        overwriteParameterValues = True
        return True

fload_handler = FamilyLoaderOptionsHandler()

OUT=fload_handler