
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi team,
I instantiated a family symbol (a door) using the following code:
FamilyInstance instance = doc.Create.NewFamilyInstance(
new XYZ(),
familySymbol,
doc.GetElement(familySymbol.LevelId) as Level,
Autodesk.Revit.DB.Structure.StructuralType.UnknownFraming
);
However, the catch is this FamilySymbol (the door) is dependent on another FamilySymbol (a doorknob).
So when I try to hide the door:
view.HideElements(new List<ElementId> { instance.id });
The door is hidden, but the doorknob is left there.
How do I hide both the door and doorknob?
I tried to get the dependent element of the door, like so:
ElementFilter ef = new ElementClassFilter(typeof(FamilyInstance));
IList<ElementId> dependentElements = instance.GetDependentElements(ef);
foreach (ElementId id in dependentElements)
{
Debug.WriteLine(doc.GetElement(id).Name);
}
but Revit just crashes unexpectedly., so no stack trace/ error message is available.
Important Note:
The doorSymbol and its doorknobSymbol is copied over from the original document and spawned in a different document.
// copy over the symbol to spawn into the new document
Family fam = uiapp.ActiveUIDocument.Document.EditFamily(doorSymbol.Family).LoadFamily(doc);
May I know how to resolve this issue? I need to hide both the door and its dependent family.
Attached is the revit family.
Solved! Go to Solution.