Change pipe type -Error

Last few weeks I am working on a script to change pipe type from one to another.In the sample file I have attached I tried to change water pipes to gas pipes.But I am getting an error as shown below.I have incorporated error handing also with the help of @c.poupin .

can anybody help to resolve this error. @Kulkul @Nick_Boyts @SeanP @Vikram_Subbaiah @JacobSmall @Marcel_Rijsmus @sovitek

Change pipe type jOBIN Testing.dyn (116.7 KB)

WeTransfer link of sample revit File

Can you start by showing your graph (with all the node preview bubbles turned on and python code displayed) and explaining what you’re specifically trying to do with it?

1 Like

@j.sunnyT6MVA It is working perfectly from my side, I think you need to close Dynamo then reopen it when encountering such problems, I would recommend using the OOTB Element.ElementType node…Moreover, if you are running the script in 2021and above, there are some deprecated properties in the API, such as UnitType.

1 Like

There is a UI interface as shown below.

It means that all the water supply pipe network need to be converted to gas pipe type including the fittings as defined inside routing preference of gas pipe.

In the final python node shown below I am changing the type of each element one by one using a for loop.

if there is any error occuring in the above process as shown below, we are trying to resolve those errors using error handling methods.

If I can collect elements which cannot be converted (means if an error occurs while changing type), I would be happy.

Is it working for the sample Revit file I have attached.?,Is it converting the entire water supply pipes to gas incluing the fittings(Note: For gas it is welded fittings defined inside its routing preference…means all threaded fittings of water supply pipes need to be converted into welded fittings also).

the error appears because IFailuresPreprocessor interface solve automatically the errors with potentially elements deletion.
After the transaction, checking each element with propriety IsValidObject solve this problem

import clr
import sys
import System
from System.Collections.Generic import List
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

#import Revit API
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

#import Revit APIUI namespace
from Autodesk.Revit.UI import *

import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

toList = lambda x : x if hasattr(x, '__iter__') else [x]

lstelems = toList(UnwrapElement(IN[0]))
typeReplace = UnwrapElement(IN[1])
lstErrorElementIds = []
lstSuccessElements = []

class CreateFailureAdvancedHandler(IFailuresPreprocessor): #You can get information out, but you would need to create your own class to store the information. IFailurePreprocessor is more for resolving the messages beforehand.
	def __init__(self):
		self.lstErrorElementIds = []
	def PreprocessFailures(self, failuresAccessor): #The implementation of the PreprocessFailures method has an argument failuresAccessor which is used for reviewing and dealing with failure messages.
		failMessages = failuresAccessor.GetFailureMessages()
		if failMessages.Count == 0:
			return FailureProcessingResult.Continue
		transName = failuresAccessor.GetTransactionName()  #Retrieves the name of the transaction for which failures are being processed.
		if transName == "ChangeTypeFitting":
			# if alert is an warn remove it 
			if failuresAccessor.GetSeverity() == FailureSeverity.Warning:
				for currentMessage in failMessages:	
				return FailureProcessingResult.Continue
			# if alert is an error resolve it (by delete elements or by split group etc...)       
			elif failuresAccessor.GetSeverity() == FailureSeverity.Error:
				for currentMessage in failMessages:
				return FailureProcessingResult.ProceedWithCommit
		return FailureProcessingResult.Continue


with Transaction(doc) as t:
	failureOptions = t.GetFailureHandlingOptions() 
	handler = CreateFailureAdvancedHandler()
	for e,typd in zip(lstelems,typeReplace):

lstSuccessElements = [x for x in lstelems if x.IsValidObject and  x.Id not in handler.lstErrorElementIds]
lstErrorElements = [x for x in lstelems if x.IsValidObject and  x.Id in handler.lstErrorElementIds]

OUT = lstSuccessElements,lstErrorElements

Okay Thanks…Let me check once.