DynamoDS / DynamoRevit

Dynamo Libraries for Revit
https://dynamobim.org
342 stars 188 forks source link

TypeError: No method matches given arguments for #2850

Open tibicen opened 2 years ago

tibicen commented 2 years ago

Dynamo version

Dynamo Core 2.13.1.3887 Dynamo Revit 2.13.1.3891 Cpython

Revit version

2023

Operating system

Windows 10

What did you do?

I've changed Python Script node from Ipython to Cpython. The node would change viewport type. When using Cpython it failed on ChangeTypeId(result.Id).

What did you expect to see?

That ChangeTypeId would pass the ElementId object as in viewport.ChangeTypeId(element_id) Revit API -ChangeTypeId .

What did you see instead?

The node prompt an error:

TypeError: 
No method matches given arguments for ChangeTypeId: 
(<class 'Autodesk.Revit.DB.Viewport>, <class 'Autodesk.Revit.DB.ElementId'>)
 ... 

Below is minimal code puted in the node for recreation of error:

viewports = [v1,v2,... ]  # list of unwrapped viewports from IN[0]
NAMES = ["Name_that_is_in_the_revit_file"]
result = None
collector = FilteredElementCollector(doc).OfClass(ElementType).ToElements()
for e in collector:
    title = e.LookupParameter("Title")
    if title is not None:
        name = e.LookupParameter("Type Name").AsValueString()
        if name in NAMES:
            result = e
            break

if result:
    TransactionManager.Instance.EnsureInTransaction(doc)
    for x in viewports:
        x.ChangeTypeId(result.Id)  # MAIN PROBLEM
    TransactionManager.Instance.TransactionTaskDone()

I've found an info on github repository about similar problem solved in Dynamo 2.8, and it is possible I'm doing something wrong. But for me I've double checked al the types of the objects.

mjkkirschner commented 2 years ago

There are still many reported issues with overloading in the version of PythonNet Dynamo uses - you can try casting the types in the method call and see if that helps.

I think this example could also be used as a workaround if absolutely necessary using reflection: https://forum.dynamobim.com/t/new-feature-preview-python-3-support-issue-thread/51649/116

to cast the type try x.ChangeTypeId[ElementId](result.Id)

miguelmaso commented 1 year ago

I have the same issue. e.ChangeTypeId(e.GetTypeId()) throws:

TypeError: No method matches given arguments for ChangeTypeId: (<class 'Autodesk.Revit.DB.FamilyInstance'>, <class 'Autodesk.Revit.DB.ElementId'>)

and e.ChangeTypeId[DB.ElementId](e.GetTypeId()) did not work:

TypeError: No match found for given type params

Dynamo Core 2.17.0.3472 Dynamo Revit 2.17.0.7404 Revit 2024 Windows 10

Amoursol commented 7 months ago

@tibicen @miguelmaso We have plans to update the PythonNET bridge project as per our roadmap that should resolve a lot of CPython parity issues with IronPython. We're not yet sure of the full extent, but it should be significantly better than today.