Hello everyone
I have a family which is nested in multiple familly and i want to update it in all th familly where it is used, i have tried going throught python using dynamo but it’s not working and i can’t tell why
below the script written
i can tell where the issue is but i don’t know how to solve it
I HOPE SOMEONE CAN HELP ME;
Would be simpler to help if you posted the code rather than a screen shot.
As an aside - this is really what shared nested families are for. One reload and all families are updated. No code required.
1 Like
Oh sorry, i’ll post the code below here
As for the nested familly i understand what you are saying, what i dont want to do is opening each familly and reload the nested inside each of them. i wanted to access the families and reload the nested familly in each of them.
here’s the code
import clr
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
# Get the active document
doc = DocumentManager.Instance.CurrentDBDocument
# Dynamo Inputs
ventouse_name = IN[0] # Name of the nested family to update (e.g., "Ventouse")
new_ventouse_path = IN[1] # Path to the updated .rfa file (e.g., "C:/Families/Ventouse_v2.rfa")
# Filter only door families
collector = FilteredElementCollector(doc).OfClass(Family).WhereElementIsNotElementType()
door_families = [fam for fam in collector if fam.FamilyCategory and fam.FamilyCategory.Id.IntegerValue == BuiltInCategory.OST_Doors]
# List of door families to modify
families_to_update = []
# Search for doors containing the "Ventouse" family
for door_family in door_families:
if door_family.IsEditable: # Check if the family is editable
door_family_doc = doc.EditFamily(door_family) # Open the family in edit mode
# Search for nested families
instances = FilteredElementCollector(door_family_doc).OfClass(FamilyInstance)
for instance in instances:
if instance.Symbol.Family and instance.Symbol.Family.Name == ventouse_name:
families_to_update.append(door_family)
break # One occurrence is enough to confirm
# Load the updated version of the "Ventouse" family
new_ventouse = None
TransactionManager.Instance.EnsureInTransaction(doc)
success = doc.LoadFamily(new_ventouse_path)
TransactionManager.Instance.TransactionTaskDone()
if not success:
OUT = "Error loading the updated Ventouse family"
else:
# Update door families
updated_count = 0
for door_family in families_to_update:
if not door_family.IsEditable:
continue # Ignore non-editable families
door_family_doc = doc.EditFamily(door_family)
TransactionManager.Instance.EnsureInTransaction(door_family_doc)
# Replace the old Ventouse with the new one
for instance in FilteredElementCollector(door_family_doc).OfClass(FamilyInstance):
if instance.Symbol.Family.Name == ventouse_name:
instance.Symbol.Family = new_ventouse # Replacement
TransactionManager.Instance.TransactionTaskDone()
# Reload the modified door family into the project
TransactionManager.Instance.EnsureInTransaction(doc)
doc.LoadFamily(door_family_doc)
TransactionManager.Instance.TransactionTaskDone()
updated_count += 1
OUT = f"Update completed ({updated_count} door families updated and reloaded into Revit)"
Hi
try to restrict yourself to a single main loop
example (not tested)
TransactionManager.Instance.ForceCloseTransaction()
door_families = FilteredElementCollector(doc).OfClass(Family).OfCategory(BuiltInCategory.OST_Doors).WhereElementIsNotElementType()
for door_family in door_families:
if door_family.IsEditable: # Check if the family is editable
door_family_doc = doc.EditFamily(door_family) # Open the family in edit mode
# Search for nested families
instances = FilteredElementCollector(door_family_doc).OfClass(FamilyInstance)
if any (i.Symbol.Family and i.Symbol.Family.Name == ventouse_name for i in instances):
success = door_family_doc.LoadFamily(new_ventouse_path)
#
# search the new type for replacement
rule = ParameterFilterRuleFactory.CreateContainsRule(ElementId(BuiltInParameter.ALL_MODEL_TYPE_NAME), "NewVentouseType")
filter = ElementParameterFilter(rule)
new_ventouse_type = FilteredElementCollector(door_family_doc).OfClass(FamilySymbol).WherePasses(filter).FirstElement()
#.
for instance in FilteredElementCollector(door_family_doc).OfClass(FamilyInstance):
if instance.Symbol.Family.Name == ventouse_name:
instance.Symbol = new_ventouse_type
#
#
# rest of code for re-load the family in project document
# .....
# .....
# .....
# close the family document
# .....