Hello folks,
I developed a code to place stairs paths in stairs that is working fine in Revit versions 2020 & 20221. Nevertheless, when testing it in Revit 2022 it gives me the following error:
"Warning: TypeError : No method matches given arguments for ChangeTypeId: (<class 'Autodesk.Revit.DB.Architecture.StairsPath'>, <class 'Autodesk.Revit.DB.ElementId'>) [' File "<string>", line 24, in <module>\n']"
The method exists for Revit API 2022.
Please, find attached a simplifed version of the code.
Any comments will be appreciated, thanks.
import clr
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Architecture import *
doc = DocumentManager.Instance.CurrentDBDocument
# ------------------------------------------------------------------------------------------------------------------- # CODE
stairsPath = UnwrapElement(IN[0])
pathId = FilteredElementCollector(doc).OfClass(StairsPathType).FirstElementId()
TransactionManager.Instance.ForceCloseTransaction()
t = Transaction(doc, 'Test')
t.Start()
stairsPath.ChangeTypeId(pathId)
t.Commit()
OUT = None
Solved! Go to Solution.
Solved by architect.bim. Go to Solution.
Actually this method works fine in Revit 2022 too. I've just checked it using Revit Python Shell. Try to open Transaction in a bit different way, may be that helps. If not there must be some inaccurancy in your code, because the method you use if fine:
s_path_type_id = FEC(doc).OfClass(StairsPathType).FirstElementId()
with DB.Transaction(doc, 'Set Stair Path Type') as t:
t.Start()
s_path.ChangeTypeId(s_path_type_id)
t.Commit()
Actually, in Dynamo this works fine too. Check the full code and Dynamo script.
import clr
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
clr.AddReference('RevitAPI')
from Autodesk.Revit import DB
from Autodesk.Revit.DB.Architecture import StairsPathType
from Autodesk.Revit.DB import FilteredElementCollector as FEC
doc = DocumentManager.Instance.CurrentDBDocument
s_path = UnwrapElement(IN[0])
s_path_type_id = FEC(doc).OfClass(StairsPathType).FirstElementId()
with DB.Transaction(doc, 'Set Stair Path Type') as t:
t.Start()
s_path.ChangeTypeId(s_path_type_id)
t.Commit()
Hi @architect.bim, thanks so much for testing it.
You're right, it's working when using IronPython2 as Python engine. Nevertheless, when swiching the engine to CPython3 it fails.
I would like to know why it's failing for future Revit versions.
As this article says there are many reported issues with this version of Python in Dynamo. You are still able to use IronPython in Revit 2022 and the following versions (in R2023 you need to install additional Dynamo package to use IronPython2). I suggest you should use IronPython as right now it is much more stable.
Can't find what you're looking for? Ask the community or share your knowledge.