How to retrieve nested family instances in Revit API -
i'm using filteredelementcollector retrieve family instances:
var collector = new filteredelementcollector(doc, doc.activeview.id); var familyinstances = collector.ofclass(typeof(familyinstance));
this works fine families don't have nested family instances. if have in project instances of family a, , family includes instances of family b, code doesn't instances of family b. how family b instances?
i'm new revit api , seems there must simple solution couldn't find 1 online. i'm using revit 2015 if makes difference.
the familyinstances have list of families in active view (including nested , non-nested ones).
what need iterate through each familyinstance , see if root family (ie contains nested families) or nested family or none. like:
var collector = new filteredelementcollector(doc, doc.activeview.id); var familyinstances = collector.ofclass(typeof(familyinstance)); foreach (var anelem in familyinstances) { if (anelem familyinstance) { familyinstance afamilyinst = anelem familyinstance; // need skip nested family instances // since them per below if (afamilyinst.supercomponent == null) { // family root family // ie might have nested families // not nested 1 var subelements = afamilyinst.getsubcomponentids(); if (subelements.count == 0) { // no nested families system.diagnostics.debug.writeline(afamilyinst.name + " has no nested families"); } else { // has nested families foreach (var asubelemid in subelements) { var asubelem = doc.getelement(asubelemid); if (asubelem familyinstance) { system.diagnostics.debug.writeline(asubelem.name + " nested family of " + afamilyinst.name); } } } } } }
Comments
Post a Comment