Reload Family and overwrite parameter values

#1

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

#3

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.

0 Likes

#5

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.

0 Likes

#6

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

0 Likes

#7

@4bimfercesp, the syntax @Einar_Raknes uses in that post will not overwrite present families… Thats why I made the node in the first place, to ensure families were loaded. Besides is the syntax also the wrong one, which I also used until recently.

This is the correct use in the post by @Einar_Raknes
http://www.revitapidocs.com/2018/6a91dc8e-6c2b-52b9-dfc4-d56fa472852b.htm
public Family LoadFamily( Document targetDocument )

This is the way if you want to overwrite present families.
http://www.revitapidocs.com/2018/cb950c8e-f440-c6db-8563-d1dd16ef3fee.htm
public Family LoadFamily( Document targetDocument, IFamilyLoadOptions familyLoadOptions )

1 Like

#8

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

#9

Thanks for the very helpful discussion.

0 Likes