Reload Family and overwrite parameter values

Hello
here is the correct syntax with (or without) overriding of type parameters with IronPython

some parameters are out parameters , arguments should be passed by-reference (not supported by Python, arguments are always passed by-value).
In the example below the out paramter overwriteParameterValues is received as a clr.Reference[T] instance* and is set with the Value property

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

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

class FamilyOption(IFamilyLoadOptions) :
	def OnFamilyFound(self, familyInUse, overwriteParameterValues):
		overwriteParameterValues.Value = False
		return True

	def OnSharedFamilyFound(self, sharedFamily, familyInUse, source, overwriteParameterValues):
		overwriteParameterValues.Value = False
		source.Value = FamilySource.Project
		return True

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

TransactionManager.Instance.EnsureInTransaction(doc)

loadedFam = []
opts = FamilyOption()
for path in pathsFamily :
	refFam = clr.Reference[Family]()
	doc.LoadFamily(path, opts, refFam)
	loadedFam.append(refFam.Value)

TransactionManager.Instance.TransactionTaskDone()

OUT = loadedFam

documentation
https://ironpython.net/documentation/dotnet/dotnet.html#methods-with-ref-or-out-parameters

2 Likes