Change type id of a set of pipe fittings

Hi All,
I am trying to change type id of a set of pipe fittings at once.I used the revit api method as shown below…anybody know how to apply this method?..now i am getting an error which says 'ChangeTypeId is not defined".


image

i tried to change family type of fitting one at a time using the methodElement.ChangeType(ElementId) but its giving me following error.
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 82, in
Exception: The referenced object is not valid, possibly because it has been deleted from the database, or its creation was undone.

Here is the full code


# Enable Python support and load DesignScript library
import clr
import sys
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference('DSCoreNodes')
from DSCore.List import Flatten



import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

#for Using  C# List 
import System
from System.Collections.Generic import*

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

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

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

import collections

def get_unique_elementid(Elementsid):
	Elements_IdIntegerValue = []
	for id in Elementsid:
		Elements_IdIntegerValue.append(id.IntegerValue)
	
	Unique_Elementsid = []
	for id in Elements_IdIntegerValue:
		if id not in Unique_Elementsid:
			Unique_Elementsid.append(id)
	
	
			
	return Unique_Elementsid

# The inputs to this node will be stored as a list in the IN variables.
Element_List = UnwrapElement(IN[0])
TypeId_List = UnwrapElement(IN[1])
TypeId_List_Unique = []
Element_Seperate_List = []
# Place your code below this line
#CList_ElementId = List[ElementId]()

#for TypeId in TypeId_List:
	#CList_ElementId.Add(TypeId)
TransactionManager.Instance.EnsureInTransaction(doc)	
TypeId_List_Unique_int = get_unique_elementid(TypeId_List)
TypeId_List_Unique_id = []
for TypeId in TypeId_List_Unique_int:
	Element_Seperate_List_inter = []
	for element,Typeid in zip(Flatten(Element_List),Flatten(TypeId_List)):
		if TypeId == Typeid.IntegerValue:
			Element_Seperate_List_inter.append(element)
	Element_Seperate_List.append(Element_Seperate_List_inter)
for i in TypeId_List_Unique_int:
	TypeId_List_Unique_id.append(ElementId(i))
Output = []	
test = []
for TypeId,Element_List in zip(TypeId_List_Unique_id,Element_Seperate_List):
	CList_ElementId = List[ElementId]()
	
	for Element in Element_List:
		Element.ChangeTypeId(TypeId)
	doc.Regenerate()	
		#CList_ElementId.Add(Element.Id)	
		#test.append(Element.IsValidType(TypeId))
	#ChangeTypeId(doc,CList_ElementId,TypeId)
# Assign your output to the OUT variable.
TransactionManager.Instance.TransactionTaskDone()

OUT = TypeId_List_Unique_id

Hello @j.sunnyT6MVA
I don’t know the structure of your input lists, but your script works for me, what’s your Revit version? Can you share a sample file project?

Notes:

  • avoid writing the name of your variables in Title case format

  • It’s not necessary to convert ElementId to Integer to compare them