Reload Family from Folder, without overriding parameters

Hi,

We’ve written a Dynamo graph based on Erfajo’s excellent responses to Load Revit families from list. We’ve tweaked it so that it should load families without Overwriting the type parameters of families already loaded. Unfortunately this isn’t working and the Python script still overwrites the type parameters on reloading the family.

My Python skills are poor and can’t see why “overwriteParameterValues = False” doesn’t seem to stick. I’m hoping there’s an obvious bug that someone can point out?

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 = False
return True

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

#Core data processing
TransactionManager.Instance.EnsureInTransaction(doc)

opts = FamilyOption()
for element in elements :
doc.LoadFamily(element, opts)

TransactionManager.Instance.TransactionTaskDone()

#The result (log) to the OUT variable
OUT = "Famil{} updated/reloaded".format('y is' if len(IN[0]) == 1 else 'ies are')

Ideally we would also have a boolean toggle going into the Python node which would set overwriteParameterValues to true or false as required. I notice that the dynamo node outputs lower case values e.g. “false” whilst Python required capitalised values e.g. “False” and is case sensitive. Would this work and is there a simple IF conditional that can/should be used to translate these?

Thanks!

I have the same problem. Not using dynamo, using pyrevit. But the False setting is not respected. Did you ever get it working?

Hi Mike,

No, i never got this to work. I had someone at Autodesk take a look at it but their fix didn’t work either.

Hello
some parameters are out parameters, arguments should be passed by-reference (not supported by Python, arguments are always passed by-value).

reload Family

But IronPython supports this, according the doc:
When overriding a .NET method with ref or out parameters, the ref or out paramter is received as a clr.Reference[T] instance. The incoming argument value is accessed by reading the Value property, and the resulting value is specified by setting the Value property

so the IronPython code becomes

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
        return True


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

TransactionManager.Instance.EnsureInTransaction(doc)

opts = FamilyOption()
for path in pathsFamily :
    doc.LoadFamily(path, opts)

TransactionManager.Instance.TransactionTaskDone()

OUT = pathsFamily
1 Like