void ReconstructAdaptiveComponentByPoints ( Document doc, ref Autodesk.Revit.DB.Element element, IList <Rhino.Geometry.Point3d> points, Autodesk.Revit.DB.FamilySymbol type ) { var adaptivePoints = points.ConvertAll(GeometryEncoder.ToXYZ); if (!type.IsActive) { type.Activate(); } // Type ChangeElementTypeId(ref element, type.Id); if (element is FamilyInstance instance && AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(instance)) { var adaptivePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(instance); if (adaptivePointIds.Count == adaptivePoints.Count) { int index = 0; foreach (var vertex in adaptivePointIds.Select(id => doc.GetElement(id)).Cast <ReferencePoint>()) { vertex.Position = adaptivePoints[index++]; } return; } } { var creationData = new List <Autodesk.Revit.Creation.FamilyInstanceCreationData> { Revit.ActiveUIApplication.Application.Create.NewFamilyInstanceCreationData(type, adaptivePoints) }; var newElementIds = doc.IsFamilyDocument ? doc.FamilyCreate.NewFamilyInstances2(creationData) : doc.Create.NewFamilyInstances2(creationData); if (newElementIds.Count != 1) { doc.Delete(newElementIds); throw new InvalidOperationException(); } var parametersMask = new BuiltInParameter[] { BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM, BuiltInParameter.ELEM_FAMILY_PARAM, BuiltInParameter.ELEM_TYPE_PARAM }; ReplaceElement(ref element, doc.GetElement(newElementIds.First()), parametersMask); } }
public bool AllowElement(Element e) { //try cast element to familyInstance var familyInstance = e as FamilyInstance; //if cast succeeds, check if it is an adaptive component if (familyInstance != null) { return(AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(familyInstance)); } //cast failed, therefore not an adaptive component return(false); }
public override Value Evaluate(FSharpList <Value> args) { var instance = (FamilyInstance)((Value.Container)args[0]).Item; // ADAPTIVE COMPONENT if (AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(instance)) { var refPtIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(instance); FSharpList <Value> refPts = FSharpList <Value> .Empty; foreach (var id in refPtIds) { var pt = dynRevitSettings.Doc.Document.GetElement(id) as ReferencePoint; refPts = FSharpList <Value> .Cons(Value.NewContainer(pt.Position), refPts); } return(Value.NewList(Utils.SequenceToFSharpList(refPts.Reverse()))); } // INSTANCE WITH PLACEMENT POINT var ptRefs = instance.GetFamilyPointPlacementReferences(); if (ptRefs.Any()) { var pts = ptRefs.Select(x => x.Location.Origin); var containers = pts.Select(Value.NewContainer); return(Value.NewList(Utils.SequenceToFSharpList(containers))); } LocationPoint point = null; LocationCurve c = null; // INSTANCE WITH LOCATION POINT point = instance.Location as LocationPoint; if (point != null) { return(Value.NewContainer(point.Point)); } //INSTANCE WITH LOCATION CURVE c = instance.Location as LocationCurve; if (c != null) { return(Value.NewContainer(c.Curve)); } throw new Exception("A location could not be found for the selected family instance(s)."); }
internal void AssertValidSpeckleElement(DB.Element elem, Base spkElem) { Assert.NotNull(elem); Assert.NotNull(spkElem); Assert.NotNull(spkElem["parameters"]); Assert.NotNull(spkElem["elementId"]); // HACK: This is not reliable or acceptable as a testing strategy. if (!(elem is DB.Architecture.Room || elem is DB.Mechanical.Duct || AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(elem as FamilyInstance))) { Assert.Equal(elem.Name, spkElem["type"]); } //Assert.NotNull(spkElem.baseGeometry); //Assert.NotNull(spkElem.level); //Assert.NotNull(spkRevit.displayMesh); }
/// <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); }
public static bool IsAdaptiveComponent(Element elem) { return (GCInstance.IsInstance(elem) && AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(elem as FamilyInstance)); }
public static bool TryGetAdaptiveComponentPoint3Ds(this FamilyInstance familyInstance, out List <Point3D> point3Ds, out List <Point3D> point3Ds_Placement, out List <Point3D> point3Ds_ShapeHandle) { point3Ds = null; point3Ds_Placement = null; point3Ds_ShapeHandle = null; if (familyInstance == null) { return(false); } if (!AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(familyInstance)) { return(false); } Document document = familyInstance.Document; IList <ElementId> elementIds = null; elementIds = AdaptiveComponentInstanceUtils.GetInstancePointElementRefIds(familyInstance); if (elementIds != null) { point3Ds = new List <Point3D>(); foreach (ElementId elementId in elementIds) { ReferencePoint referencePoint = document.GetElement(elementId) as ReferencePoint; if (referencePoint == null || referencePoint.Position == null) { continue; } point3Ds.Add(referencePoint.Position.ToSAM()); } } elementIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(familyInstance); if (elementIds != null) { point3Ds_Placement = new List <Point3D>(); foreach (ElementId elementId in elementIds) { ReferencePoint referencePoint = document.GetElement(elementId) as ReferencePoint; if (referencePoint == null || referencePoint.Position == null) { continue; } point3Ds_Placement.Add(referencePoint.Position.ToSAM()); } } elementIds = AdaptiveComponentInstanceUtils.GetInstanceShapeHandlePointElementRefIds(familyInstance); if (elementIds != null) { point3Ds_ShapeHandle = new List <Point3D>(); foreach (ElementId elementId in elementIds) { ReferencePoint referencePoint = document.GetElement(elementId) as ReferencePoint; if (referencePoint == null || referencePoint.Position == null) { continue; } point3Ds_ShapeHandle.Add(referencePoint.Position.ToSAM()); } } return(true); }
/***************************************************/ public static IEnumerable <IBHoMObject> FromRevit(this FamilyInstance familyInstance, Discipline discipline, Transform transform = null, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { if (AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(familyInstance)) { BH.oM.Adapters.Revit.Elements.ModelInstance instance = familyInstance.ModelInstanceFromRevit(settings, refObjects); if (instance != null && transform?.IsIdentity == false) { TransformMatrix bHoMTransform = transform.FromRevit(); instance = instance.Transform(bHoMTransform) as BH.oM.Adapters.Revit.Elements.ModelInstance; } return(new List <IBHoMObject> { instance }); } else { IEnumerable <IElement> result = null; switch (discipline) { case Discipline.Structural: if (typeof(Bar).BuiltInCategories().Contains((BuiltInCategory)familyInstance.Category.Id.IntegerValue)) { result = familyInstance.BarsFromRevit(settings, refObjects); } break; case Discipline.Physical: case Discipline.Architecture: if (typeof(BH.oM.Physical.Elements.Window).BuiltInCategories().Contains((BuiltInCategory)familyInstance.Category.Id.IntegerValue)) { result = new List <IElement> { familyInstance.WindowFromRevit(settings, refObjects) } } ; else if (typeof(BH.oM.Physical.Elements.Door).BuiltInCategories().Contains((BuiltInCategory)familyInstance.Category.Id.IntegerValue)) { result = new List <IElement> { familyInstance.DoorFromRevit(settings, refObjects) } } ; else if (typeof(BH.oM.Physical.Elements.Column).BuiltInCategories().Contains((BuiltInCategory)familyInstance.Category.Id.IntegerValue) || familyInstance.StructuralType == StructuralType.Column) { result = new List <IElement> { familyInstance.ColumnFromRevit(settings, refObjects) } } ; else if (typeof(BH.oM.Physical.Elements.Bracing).BuiltInCategories().Contains((BuiltInCategory)familyInstance.Category.Id.IntegerValue) || familyInstance.StructuralType == StructuralType.Brace) { result = new List <IElement> { familyInstance.BracingFromRevit(settings, refObjects) } } ; else if (typeof(BH.oM.Physical.Elements.Beam).BuiltInCategories().Contains((BuiltInCategory)familyInstance.Category.Id.IntegerValue)) { result = new List <IElement> { familyInstance.BeamFromRevit(settings, refObjects) } } ; break; case Discipline.Environmental: result = new List <IElement> { familyInstance.EnvironmentPanelFromRevit(settings, refObjects) }; break; case Discipline.Facade: if (typeof(BH.oM.Facade.Elements.Opening).BuiltInCategories().Contains((BuiltInCategory)familyInstance.Category.Id.IntegerValue)) { result = new List <IElement> { familyInstance.FacadeOpeningFromRevit(settings, refObjects) } } ; else if (typeof(BH.oM.Facade.Elements.FrameEdge).BuiltInCategories().Contains((BuiltInCategory)familyInstance.Category.Id.IntegerValue)) { result = new List <IElement> { familyInstance.FrameEdgeFromRevit(settings, refObjects) } } ; break; } if (result != null && transform?.IsIdentity == false) { TransformMatrix bHoMTransform = transform.FromRevit(); result = result.Select(x => x?.ITransform(bHoMTransform)); } return(result?.Cast <IBHoMObject>().ToList()); } }
private void MatchElementsToAlignments() { // find all elements for the curves (railings and sleepers) var railParts = new FilteredElementCollector(_document) .OfClass(typeof(FamilyInstance)) .ToElements() .Cast <FamilyInstance>() .Where(e => AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(e)) .ToList(); foreach (var element in railParts) { // get adaptive points var points = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(element) .Select(r => _document.GetElement(r)) .Cast <ReferencePoint>() .ToList(); // match addaptive points to curves if (points.Count > 0) { foreach (var record in _alignments) { if (ArePointsOnCurve(record.Polylines, points)) { // find IFC element IfcGloballyUniqueId id = GetIfcGUID(element); var ifcElement = i.FirstOrDefault <IfcBuildingElement>(e => e.GlobalId == id); if (ifcElement != null) { record.Elements.Add(ifcElement); } } } } } // find building elements which were not matched, possibly because they were not modelled with adaptive points var notMatched = i.Where <IfcBuildingElement>(e => !_alignments.Any(a => a.Elements.Contains(e))) .ToList(); foreach (var element in notMatched) { var matrix = GetMatrixRelativeToSite(element); var position = matrix.Transform(new XbimPoint3D(0, 0, 0)); Intersection intersection = null; AlignmentRecord record = null; // find closes alignment intersection (if any) foreach (var alignmentRecord in _alignments) { var i = GetIntersection2D(alignmentRecord.Segments.ToList(), position); if (i == null) { continue; } if (intersection == null || Math.Abs(intersection.OffsetLateral) > Math.Abs(i.OffsetLateral)) { intersection = i; record = alignmentRecord; } } // we found one working so lets use it if (record != null) { record.Elements.Add(element); } } }