Identify GeometryObject in family instance NOT within a nested family instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I am attempting to write a plugin that can parse an instance for a nested family that contains both GeometryObjects as well as family instances nested within the top-level family instance. I've attached an example project that includes a single instance for the "test-table" family that I created. You will notice that the "test-table" family definition contains four instances to "test-leg", which represent the legs of the table, as well as two extrusions, one for the table surface and one for the cylinder sitting on top of the table.
I would like to be able to pull the nested families (i.e. the four instances for "test-leg", pointed to by red arrows in attached picture) as well as any geometry information that is not within the nested family (i.e. the table top and the cylinder, pointed to by blue arrows in attached picture). I have seen examples online to pull the nested families, but I haven't been able to find anything for just getting geometry objects NOT inside the nested family instances (using something like "familyInstance.get_Geometry(options)" and iterating over those results will include the geometry objects from everything, including within the nested family instances).
Below is the code I'm working with, which will write output lines for the four "test-leg" instances only. Thanks!
List<string> logs = new List<string>();
List<FamilyInstance> tables = new FilteredElementCollector(document)
.OfCategory(BuiltInCategory.OST_GenericModel)
.WhereElementIsNotElementType()
.OfType<FamilyInstance>()
.Where(instance => instance.Symbol.FamilyName.Contains("test-table"))
.Where(Instance => Instance.Name.Contains("test-table"))
.ToList();
logs.Add($"Number of tables found: {tables.Count}");
int tableCount = 0;
foreach (FamilyInstance table in tables)
{
logs.Add($"Examining table #{++tableCount}");
Family family = table.Symbol.Family;
Document familyDoc = document.EditFamily(family);
if (familyDoc == null || !familyDoc.IsFamilyDocument)
{
logs.Add("No family doc found!");
}
// TODO: Unclear on how to get GeometryObjects from familyDoc without also getting those within nested family instances
List<FamilyInstance> familyInstances = new FilteredElementCollector(familyDoc)
.OfCategory(BuiltInCategory.OST_GenericModel)
.WhereElementIsNotElementType()
.OfType<FamilyInstance>()
.ToList();
foreach (FamilyInstance familyInstance in familyInstances)
{
logs.Add($"Nested family instance found: type={familyInstance.GetType()}, name={familyInstance.Name}");
}
}
File.WriteAllLines("/path/to/log.txt", logs.ToArray());
The above will output the below:
Number of tables found: 1
Examining table #1
Nested family instance found: type=Autodesk.Revit.DB.FamilyInstance, name=test-leg
Nested family instance found: type=Autodesk.Revit.DB.FamilyInstance, name=test-leg
Nested family instance found: type=Autodesk.Revit.DB.FamilyInstance, name=test-leg
Nested family instance found: type=Autodesk.Revit.DB.FamilyInstance, name=test-leg