/// <summary> /// Gets the hosted element of a host and adds the to a Base object /// </summary> /// <param name="host"></param> /// <param name="base"></param> public void GetHostedElements(Base @base, HostObject host) { var hostedElementIds = host.FindInserts(true, true, true, true); var convertedHostedElements = new List <Base>(); if (!hostedElementIds.Any()) { return; } var elementIndex = ContextObjects.FindIndex(obj => obj.applicationId == host.UniqueId); if (elementIndex != -1) { ContextObjects.RemoveAt(elementIndex); } foreach (var elemId in hostedElementIds) { var element = Doc.GetElement(elemId); var isSelectedInContextObjects = ContextObjects.FindIndex(x => x.applicationId == element.UniqueId); if (isSelectedInContextObjects == -1) { continue; } ContextObjects.RemoveAt(isSelectedInContextObjects); if (CanConvertToSpeckle(element)) { var obj = ConvertToSpeckle(element); if (obj != null) { convertedHostedElements.Add(obj); ConvertedObjectsList.Add(obj.applicationId); } } } if (convertedHostedElements.Any()) { if (@base["elements"] == null || !(@base["elements"] is List <Base>)) { @base["elements"] = new List <Base>(); } (@base["elements"] as List <Base>).AddRange(convertedHostedElements); } }
/// <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); }