Reload Family and overwrite parameter values

Hello everyone,

I have a problem when I used below code to reload families. The families were loaded but graphic only(Overwrite the existing version) . Type Parameters were not overwrite. I checked in this code and find out the variable “overwriteParameterValues” is True. When I changed to False , the families could not be loaded.

Many thanks,

Load multiple families from a folder

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

#Inputs is stored in the IN variable
elements = IN[0]

#Ensure loaded families can overwrite existing families.
class FamilyOption(IFamilyLoadOptions) :
def OnFamilyFound(self, familyInUse, overwriteParameterValues) :
	overwriteParameterValues = True
	return True

def OnSharedFamilyFound(self, sharedFamily, familyInUse, source, overwriteParameterValues) :
	return True

#Core data processing
TransactionManager.Instance.EnsureInTransaction(doc)
try:
for element in elements :
	doc.LoadFamily(element, FamilyOption())
except:
pass
TransactionManager.Instance.TransactionTaskDone()

#Nothing assign to the OUT variable
OUT = 'Families is updatet/reloaded'
1 Like

Hi erfajo,
Thank for you help, I think the old code is faster than the update. You don’t need open the many family files. In case you want to load many families in many documents, the first is more productive.
If you have any suggestions about Overwrite Parameter values, please inform me. I really need it now.

Thank you.

I tested your old code in Dynamo, It work well. But when I tested in Revit Add-in, It not work. It work only with new code.As you said the syntax is old, but both Dynamo and Revit add in use Revit API. I don’t know what are differents.

Hi…would the topic below your deemed to be the ultimate goal? Im just asking.

thanks for this code @erfajo!
I was afraid i might have to fire up visual studio in order to implement an interface. Awesome that a python class can inherit an interface. i never would have known…:astonished:

2 Likes

Thanks for the very helpful discussion.

@conghau.bdh, Do you have a working script in pythonto reload a family?

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