ChangeTypeId Having issue with CPython3 Engine...?

Did anyone else also encountered this issue while Changing TypeId using method ChangeTypeId being retured with a warning as shown below:


And at the same time if i change the engine it’ll execute perfectly, Weird?? :thinking:
so finally here if someone also bumped into the same, even found a unresolved thread as well seem quite old.

Hi,

see this topic

Here is an example of the function in Cpython

NewFamily=Grid.Create(doc,anycurve)
        if NewFamily:
                GPI = NewFamily.GetType().GetMethod("ChangeTypeId")
                GPI.Invoke(NewFamily, [ElementId(AnyGridType.Id)])

Create new family or existing.
Get the righte Method
Use an Invoke to execute the right methode
It works for me.

Hi @c.poupin & @b.vanderhoeven

This method worked like charm but @c.poupin still curious why the other overload isn’t working the one u mentioned in previous thread, here’s an implementation of it


It’s asking for doc, Icollection and ElementId. All 3 given so what did i miss…??

The second method is an static method

Oh yesssss…!!! @c.poupin Thankyou both the method working perfectly.

i missed that it was static Method, instead i was calling it as an Instance method.

Marked the solution

And glad to have this community.

2 Likes

I know this has been “solved” for a while, but I could not get this to work for me in R25 and the solution I found was to slightly modify the following line:

GPI.Invoke(person, [ElementId(types[i].Id)])

to this:

GPI.Invoke(person, [ElementId(types[i].Id.Value)])

2 Likes

FYI, it has been solved using the new PythonNet3 engine.

1 Like

Thanks @c.poupin, I been out of the Dynamo python game for a bit, but didn’t think to try the same idea within the normal method.

2 Likes

Dear specialist,

I am working in Revit2025 and downloaded PythonNet3.
I have the following problem.

The model element of upper node is the element to change. And the lower node is elem which Viewport Type have to be used for the upper node element. How could I fix it?

import clr

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

# Revit Services
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Dynamo / Revit wrapper helpers
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Document
doc = DocumentManager.Instance.CurrentDBDocument

# Unwrap input element (Dynamo wrapper → Revit API)
elemToChange = UnwrapElement(IN[0])
elemFromChange = UnwrapElement(IN[1]) 
elemID_new = elemFromChange.GetTypeId()

# Begin transaction
TransactionManager.Instance.EnsureInTransaction(doc)

# Get type before
elemToChange.ChangeTypeId(elemID_new)

# Regenerate document
doc.Regenerate()

# End transaction
TransactionManager.Instance.TransactionTaskDone()

# Output
OUT = typeId_after

import clr

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

# Revit Services
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Dynamo / Revit wrapper helpers
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Document
doc = DocumentManager.Instance.CurrentDBDocument

# Unwrap input element (Dynamo wrapper → Revit API)
elemToChange = UnwrapElement(IN[0])
elemFromChange = UnwrapElement(IN[1]) 
elemID_new = elemFromChange.GetTypeId()

# Begin transaction
TransactionManager.Instance.EnsureInTransaction(doc)

# Get type before
Element.ChangeTypeId(doc, elementIds_to_be_changed , typeId)

# Regenerate document
doc.Regenerate()

# End transaction
TransactionManager.Instance.TransactionTaskDone()

# Output
OUT = typeId_after

Hi @rick.landkroon

Welcome to the Community,

Here u go as u could see above i have replaces one line that’ll work as there’s a static method for this u need to provide ICollection of element ids u want to change

Element.ChangeTypeId(doc, elementIds_to_be_changed , typeId)
1 Like

Thanks! This is the solution!
Why you need the PythonNet3 engine for it?

ChangeTypeId() instance method works fine with PythonNet3

You need to switch to using the PythonNet3 engine (bug with CPython3) .

1 Like