/// <summary> /// Note: not tested. Not sure what the scenarios here would be either (super families?) /// </summary> /// <param name="familyInstance"></param> /// <returns></returns> private List <DB.Element> GetAllFamSubElements(DB.FamilyInstance familyInstance) { var subElements = new List <DB.Element>(); foreach (var id in familyInstance.GetSubComponentIds()) { var element = Doc.GetElement(id); subElements.Add(element); if (element is Autodesk.Revit.DB.FamilyInstance) { subElements.AddRange(GetAllFamSubElements(element as DB.FamilyInstance)); } } return(subElements); }
public static List <Element> GetFamSubElements(Autodesk.Revit.DB.FamilyInstance myFamily) { var mySubElements = new List <Element>(); foreach (var id in myFamily.GetSubComponentIds()) { var element = Doc.GetElement(id); mySubElements.Add(element); if (element is Autodesk.Revit.DB.FamilyInstance) { mySubElements.AddRange(GetFamSubElements(element as Autodesk.Revit.DB.FamilyInstance)); } } return(mySubElements); }
/// <summary> /// Entry point for all revit family conversions. TODO: Check for Beams and Columns and any other "dedicated" speckle elements and convert them as such rather than to the generic "family instance" object. /// </summary> /// <param name="myElement"></param> /// <returns></returns> public Base FamilyInstanceToSpeckle(DB.FamilyInstance revitFi) { if (!ShouldConvertHostedElement(revitFi, revitFi.Host)) { return(null); } //adaptive components if (AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(revitFi)) { return(AdaptiveComponentToSpeckle(revitFi)); } //these elements come when the curtain wall is generated //let's not send them to speckle unless we realize they are needed! if (Categories.curtainWallSubElements.Contains(revitFi.Category)) { return(null); } //beams & braces if (Categories.beamCategories.Contains(revitFi.Category)) { if (revitFi.StructuralType == StructuralType.Beam) { return(BeamToSpeckle(revitFi)); } else if (revitFi.StructuralType == StructuralType.Brace) { return(BraceToSpeckle(revitFi)); } } //columns if (Categories.columnCategories.Contains(revitFi.Category) || revitFi.StructuralType == StructuralType.Column) { return(ColumnToSpeckle(revitFi)); } var baseGeometry = LocationToSpeckle(revitFi); var basePoint = baseGeometry as Point; if (basePoint == null) { return(RevitElementToSpeckle(revitFi)); } var lev1 = ConvertAndCacheLevel(revitFi, BuiltInParameter.FAMILY_LEVEL_PARAM); var lev2 = ConvertAndCacheLevel(revitFi, BuiltInParameter.FAMILY_BASE_LEVEL_PARAM); var symbol = Doc.GetElement(revitFi.GetTypeId()) as FamilySymbol; var speckleFi = new BuiltElements.Revit.FamilyInstance(); speckleFi.basePoint = basePoint; speckleFi.family = symbol.FamilyName; speckleFi.type = symbol.Name; speckleFi.category = revitFi.Category.Name; speckleFi.facingFlipped = revitFi.FacingFlipped; speckleFi.handFlipped = revitFi.HandFlipped; speckleFi.level = lev1 != null ? lev1 : lev2; if (revitFi.Location is LocationPoint) { speckleFi.rotation = ((LocationPoint)revitFi.Location).Rotation; } speckleFi.displayMesh = GetElementMesh(revitFi, GetAllFamSubElements(revitFi)); GetAllRevitParamsAndIds(speckleFi, revitFi); #region sub elements capture var subElementIds = revitFi.GetSubComponentIds(); var convertedSubElements = new List <Base>(); foreach (var elemId in subElementIds) { var subElem = Doc.GetElement(elemId); if (CanConvertToSpeckle(subElem)) { var obj = ConvertToSpeckle(subElem); if (obj != null) { convertedSubElements.Add(obj); ConvertedObjectsList.Add(obj.applicationId); } } } if (convertedSubElements.Any()) { speckleFi.elements = convertedSubElements; } #endregion // TODO: // revitFi.GetSubelements(); //Report.Log($"Converted FamilyInstance {revitFi.Id}"); return(speckleFi); }