Reloading Families through API crashes Revit

Hi Guys,

I try to reload/ load Families into revit through the Revit API. Therefor i created following Python script:

import clr
import sys
import System 
from System.Collections.Generic import List 
import uuid #unique userID

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

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import * 
import traceback

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
#Preparing import from Dynamo to Revit 


List_ZG = IN[0] #list of paths of target families
List_Bauteile = IN[1] #list of paths of families

#Define classes & functions

#IFamilyLoadOptions Class
class FamilyLoadOptionsHandler(DB.IFamilyLoadOptions):
    __namespace__ = str(uuid.uuid4()) #defines Namespaces uniquely everytime the script runs, maybe temporary fix
    
    def OnFamilyFound (self, familyInUse, overwriteParameterValues):
        self.overwriteParameterValues = True
        return True 
        
    def OnSharedFamilyFound (self, sharedFamily, familyInUse, source, overwriteParameterValues):
        source = DB.FamilySource.Family
        self.overwriteParameterValues = True
        return True 

#actual script
count = 0
outlist = []
for ZG in List_ZG:
    for Bauteil in List_Bauteile[count]:
        try:
            #ZG_Open = app.OpenDocumentFile(ZG) #backgroundopen trarget family
            Bauteil_Open = app.OpenDocumentFile(Bauteil) #backgroundopen family
            Load = Bauteil_Open.LoadFamily(doc,FamilyLoadOptionsHandler()) #load family into target family
            Bauteil_Open.Close(False) #close family, don´t save
            #ZG_Open.Close(True) #close target family and save
            outlist.append("true") 
        except:
            new = traceback.format_exc() 
            outlist.append(new) 
    count += 1      
OUT = outlist

The problem I encouterd is that when I try to reload a Family that already exists in the Project or another Family, Revit simply crahses and closes completely without the typical error window.
Doesn´t matter if the Family changed (currently only changing the geometry without a parameter) or not and if I the target document is a Family or Project File.

Since I´m still quite new to python and Revit API I´m not sure if I would need the Transactionmanager here, still tried it didn´t change anything (atleast the way i used it).

Here are my Test-files:
Familie2.rfa (688 KB)
Familie3.rfa (688 KB)
Test_LoadFamilies.rvt (3.5 MB)
2023-07-21_Test_LoadFamilies.dyn (15.9 KB)

Currently using Revit 2024 24.0.4.427 and built in Dynamo.

The goal would be to bulk reload around 200 families into different nested Families and projects (may take some processing time but still better then doing it manually).

Thanks in advance.

1 Like