'No method matches given arguments for OnExist' error

Dear Dynamo Experts,

I have been using Dynamo script with IronPython2 node on Revit 2022, without issues for the last 2 years.

This week, I wanted to use the same Dynamo script on Revit 2025.

As Revit 2025 is now using CPython3, I immediately got the following error:

TypeError: No method matches given arguments for OnExist (<class 'Autodesk.Revit.DB'Transaction'>,<class type>, <class TypeError>, <class traceback>) ['File "<string>", line 973, in <module>\n']

The error is raised when on line: t.Commit().
Here is an excerpt of the code:

import clr
from System import Array
import System
import time
import math
import sys

clr.AddReference("System.Drawing")
clr.AddReference("System.Windows.Forms")
import System.Windows.Forms
import System.Drawing
import csv

try:
    # dynamo dlls
    clr.AddReference('ProtoGeometry')
    from Autodesk.DesignScript.Geometry import *
    
    clr.AddReference('RevitNodes')
    import Revit
    clr.ImportExtensions(Revit.Elements)
    clr.ImportExtensions(Revit.GeometryConversion)
    import Revit.Elements
    
    clr.AddReference('DSCoreNodes')
    import DSCore
    from DSCore import *
    
    clr.AddReference('RevitServices')
    import RevitServices
    from RevitServices.Persistence import DocumentManager
    from RevitServices.Transactions import TransactionManager
    
    # revit dlls
    clr.AddReference('RevitAPI')
    import Autodesk
    from Autodesk.Revit.DB import *
    import Autodesk.Revit.DB as DB
    
    clr.AddReference('RevitAPIUI')
    from Autodesk.Revit.UI.Selection import *
    
    doc = DocumentManager.Instance.CurrentDBDocument

except Exception as e:
    pass


element = UnwrapElement(IN[0])
move_vec = DB.XYZ(0,0,1)

with DB.Transaction(doc) as t:
    t.Start('transaction 1')
    el_id_L = System.Collections.Generic.List[DB.ElementId]([element.Id])
    DB.ElementTransformUtils.MoveElements(doc, el_id_L, move_vec)
    t.Commit()  # THIS LINE RAISES THE UPPER ERROR

Is this typical CPython3 vs IronPython2 error related with transactions?
I looked at Python2-to-Python3 document, but couldn’t find anything about transactions.

Does anyone have any suggestion how to solve this error?
I am quite desperate at the moment.
When I try to use the internal “Convert script to Python3” functionality inside the Python3 node - the Dynamo simply gets blocks, and crashes. The python code is longer then upper excerpt, but still the error happens on such MoveElements transaction.

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

Try removing the With statement - it isn’t doing you any favors here, and they can be problematic in CPython.

For this scope I don’t think you even need to declare the specific transaction - give the default transaction manager method a shot and see if that works. Then move into building a transaction as you would any other variable if needed - no significant speed impact otherwise.

That said, the put of the box node Element.MoveByVector will likely outperform this by a wide margin.

2 Likes

Hi @jacob.small ,

Thank you very much for the reply!

So the transaction would look like this?

element = UnwrapElement(IN[0])
move_vec = DB.XYZ(0,0,1)

t = DB.Transaction(doc)  # 'with' removed
t.Start('transaction 1')
el_id_L = System.Collections.Generic.List[DB.ElementId]([element.Id])
DB.ElementTransformUtils.MoveElements(doc, el_id_L, move_vec)
t.Commit()  # THIS LINE RAISES THE UPPER ERROR

What is the default transaction manager method?

The code is slightly larger then presented here. That’s why I have to use python node, instead of Element.MoveByVector.

Looks like it, yes. Does that fail?

See here: dynamoPython/pythonTemplates/RevitPythontemplateFile at 6e3c7f4e2a3af90cd77cc4f3fa2fbccc5070e878 ¡ Amoursol/dynamoPython ¡ GitHub

Slightly indicates ‘moving the element and then starting the Python’ is a valid option, but I get that not everything is as simple as presented and appreciate the ‘here is a simple use case’ nature of the post. :slight_smile:

1 Like

Both methods worked! Thank you very much for the help @jacob.small .

“with” in IronPython defined a scope at the end of which the “DB.Transaction” object is disposed.
It is sad that in PythonNET, there is no such thing.

Thank you once again for the help Jason!

1 Like