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'

#2

I have been testing now several times, and I have to give you… it fails from time to time, but not every time. Periodically fails do I not know how to handle. In those cases where it failed I tried to press ctrl+z in the document, and then rerun the graph, in those cases it then did update!?

I really dont have any good suggestions why this is the case.

However, have I updated some parts of the code…
It is “OnSharedFamilyFound” and “LoadFamily” that is updated.

please see here also
-http://thebuildingcoder.typepad.com/blog/2011/06/reloading-a-family.html

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
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

#input assigned the IN variable
paths = IN[0]

#wrap input inside a list (if not a list)
if not isinstance(paths, list): paths = [paths]

#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):
		source = FamilySource.Family
		overwriteParameterValues = True
		return True

#core data processing
for path in paths:
	try:
		famDoc = app.OpenDocumentFile(path)
		famDoc.LoadFamily(doc, FamilyOption())
		famDoc.Close(False)
	except:
		pass

#output assigned the OUT variable
OUT = paths

#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.


#4

Well, the old way is actually not correct anymore, and has been outdated for several years. I was just lucky that it still worked. However, if you try to load families from an older version into a project, then you will figure it doesnt work anymore! Then you need to do it the proper way.

see here http://www.revitapidocs.com/2018/cb950c8e-f440-c6db-8563-d1dd16ef3fee.htm
and as I wrote… se here http://thebuildingcoder.typepad.com/blog/2011/06/reloading-a-family.html


#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.


#6

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


#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 )


#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: