public static IFramingElement SetGeometry(this IFramingElement framingElement, ICurve curve) { IFramingElement clone = (IFramingElement)framingElement.GetShallowClone(); clone.Location = curve.IClone(); return(clone); }
public static MaterialComposition MaterialComposition(this IFramingElement framingElement) { if (framingElement.Property == null) { Engine.Reflection.Compute.RecordError("The IFramingElement MaterialComposition could not be calculated as no Property has been assigned."); return(null); } return(framingElement.Property.IMaterialComposition()); }
public static double SolidVolume(this IFramingElement framingElement) { if (framingElement.Property == null) { Engine.Reflection.Compute.RecordError("The IFramingElement Solid Volume could not be calculated as no property has been assigned. Returning zero volume."); return(0); } return(framingElement.Location.Length() * IAverageProfileArea(framingElement.Property)); }
public static IGeometry Geometry3D(this IFramingElement framingElement) { if (framingElement == null) { BH.Engine.Reflection.Compute.RecordError("Cannot query the 3D Geometry of a null framing element."); return(null); } if (framingElement.Location == null) { BH.Engine.Reflection.Compute.RecordError($"Cannot compute the Geometry3D for this {nameof(IFramingElement)} because its `{nameof(IFramingElement.Location)}` is null."); return(null); } Line line = framingElement.Location as Line; if (line == null) { Polyline pl = framingElement.Location as Polyline; if (pl != null) { line = new Line() { Start = pl.ControlPoints.First(), End = pl.ControlPoints.Last() }; } if (pl == null || (pl != null && pl.ControlPoints.Count() > 2)) { BH.Engine.Reflection.Compute.RecordWarning($"Geometry3D for {nameof(IFramingElement)} currently works only if it has its {nameof(IFramingElement.Location)} defined as a {nameof(Line)}. Proceeding by taking Start/End point of the provided {framingElement.Location.GetType().Name}."); } } Vector extrusionVec = BH.Engine.Geometry.Create.Vector(line.Start, line.End); Vector normal = line.ElementNormal(0); IFramingElementProperty prop = framingElement.Property; ConstantFramingProperty constantFramingProperty = prop as ConstantFramingProperty; if (constantFramingProperty == null) { BH.Engine.Reflection.Compute.RecordError($"Geometry3D for {nameof(IFramingElement)} currently works only if its {nameof(IFramingElement.Property)} is of type {nameof(ConstantFramingProperty)}."); return(null); } List <ICurve> profileToExtrude = constantFramingProperty.Profile.Edges.ToList(); if (profileToExtrude == null || !profileToExtrude.Any()) { BH.Engine.Reflection.Compute.RecordError($"Geometry3D error: could not gather the profile curve to be extruded for this {framingElement.GetType().Name}."); return(null); } TransformMatrix totalTransform = SectionTranformation(line.Start, extrusionVec.Normalise(), normal); return(Extrude(profileToExtrude, totalTransform, extrusionVec)); }
/***************************************************/ internal static void FramingCurveNotFoundWarning(this IFramingElement framingElement) { string message = "Driving curve of a BHoM framing element could not be retrieved."; if (framingElement != null) { message = string.Format("{0} BHoM_Guid: {1}", message, framingElement.BHoM_Guid); } BH.Engine.Reflection.Compute.RecordWarning(message); }
public static IFramingElement SetGeometry(this IFramingElement framingElement, ICurve curve) { if(framingElement == null) { BH.Engine.Reflection.Compute.RecordError("Cannot set the geometry of a null framing element."); return null; } IFramingElement clone = framingElement.ShallowClone(); clone.Location = curve.DeepClone(); return clone; }
public static bool HasMergeablePropertiesWith(this IFramingElement element, IFramingElement other) { if (element == null || other == null) { return(false); //If either is null, then it can probably can't have its properties merged } if (element.GetType() != other.GetType()) { return(false); } if (element.Location == null || element.Location.ILength() < oM.Geometry.Tolerance.Distance || other.Location == null || other.Location.ILength() < oM.Geometry.Tolerance.Distance) { return(false); } if (!element.Location.IIsLinear() || !other.Location.IIsLinear()) { Engine.Reflection.Compute.RecordWarning("No merge comparison avalible for non-linear IFramingElements."); return(false); } int parallel = element.Location.IStartDir().IsParallel(other.Location.IStartDir()); if (parallel != 1) { return(false); } if (element.Normal().Angle(other.Normal()) > BH.oM.Geometry.Tolerance.Angle) { return(false); } if (element.Property == other.Property) { return(true); } if (element.Property == null || other.Property == null) { return(false); } if (element.Property.Name != other.Property.Name) { return(false); } return(Diffing.Query.DifferentProperties(element.Property, other.Property, new DiffingConfig()) == null); }
public static MaterialComposition MaterialComposition(this IFramingElement framingElement) { if (framingElement == null) { BH.Engine.Reflection.Compute.RecordError("Cannot query the material composition of a null framing element."); return(null); } if (framingElement.Property == null) { Engine.Reflection.Compute.RecordError("The MaterialComposition could not be queried as no Property has been assigned to the IFramingElement."); return(null); } return(framingElement.Property.IMaterialComposition()); }
public static Vector Normal(this IFramingElement framingElement) { double orientationAngle = 0; if (!(framingElement.Property is ConstantFramingProperty)) { Reflection.Compute.RecordWarning("No ConstantFramingProperty found, OrientationAngle set as 0"); } else { orientationAngle = (framingElement.Property as ConstantFramingProperty).OrientationAngle; } return(framingElement.Location.ElementNormal(orientationAngle)); }
/***************************************************/ public static bool SetLocation(this FamilyInstance element, IFramingElement framingElement, RevitSettings settings) { if (!(typeof(IFramingElement).BuiltInCategories().Contains((BuiltInCategory)element.Category.Id.IntegerValue))) { return(false); } double rotation = 0; ConstantFramingProperty framingProperty = framingElement.Property as ConstantFramingProperty; if (framingProperty == null) { BH.Engine.Reflection.Compute.RecordWarning(String.Format("BHoM object's property is not a ConstantFramingProperty, therefore its orientation angle could not be retrieved. BHoM_Guid: {0}", framingElement.BHoM_Guid)); } else { rotation = ((ConstantFramingProperty)framingElement.Property).OrientationAngle; } if (element.LookupParameterInteger(BuiltInParameter.YZ_JUSTIFICATION) == 1) { BH.Engine.Reflection.Compute.RecordWarning(String.Format("Pushing of framing elements with non-uniform offsets at ends is currently not supported. yz Justification parameter has been set to Uniform. Revit ElementId: {0}", element.Id)); element.SetParameter(BuiltInParameter.YZ_JUSTIFICATION, 0); element.Document.Regenerate(); } bool updated = element.SetLocation(framingElement.Location, settings); element.Document.Regenerate(); double rotationDifference = element.OrientationAngleFraming(settings) - rotation; if (Math.Abs(rotationDifference) > settings.AngleTolerance) { double newRotation = (element.LookupParameterDouble(BuiltInParameter.STRUCTURAL_BEND_DIR_ANGLE) + rotationDifference).NormalizeAngleDomain(); updated |= element.SetParameter(BuiltInParameter.STRUCTURAL_BEND_DIR_ANGLE, newRotation); element.Document.Regenerate(); } ICurve transformedCurve = framingElement.AdjustedLocationCurveFraming((FamilyInstance)element, settings); updated |= element.SetLocation(transformedCurve, settings); return(updated); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static bool SetType(this FamilyInstance element, IFramingElement bHoMObject, RevitSettings settings) { Document doc = element.Document; FamilySymbol familySymbol = bHoMObject.Property.ToRevitElementType(doc, bHoMObject.BuiltInCategories(doc), settings); if (familySymbol == null) { familySymbol = bHoMObject.IElementType(doc, settings) as FamilySymbol; } if (familySymbol == null) { Compute.ElementTypeNotFoundWarning(bHoMObject); return(false); } return(element.SetParameter(BuiltInParameter.ELEM_TYPE_PARAM, familySymbol.Id)); }
public static ICurve TopCentreline(this IFramingElement element) { if (element == null) { BH.Engine.Reflection.Compute.RecordError("Cannot query the top centreline of a null framing element."); return(null); } ICurve location = element.Location; Vector normal = null; try { normal = BH.Engine.Physical.Query.Normal(element); } catch { Engine.Reflection.Compute.RecordError("IFramingElement must have linear location line."); return(null); } if (normal == null) { Engine.Reflection.Compute.RecordError("Was not able to compute element normal."); return(null); } if (element.Property is ConstantFramingProperty) { ConstantFramingProperty constantProperty = element.Property as ConstantFramingProperty; IProfile profile = constantProperty.Profile; BoundingBox profileBounds = profile.Edges.Bounds(); return(location.ITranslate(normal * profileBounds.Max.Y)); } else { Engine.Reflection.Compute.RecordError("Element does not have a suitable framing property, so the section height could not be calculated."); return(null); } }
public static double Elevation(this IFramingElement obj, ElevationFrom elevationFrom = ElevationFrom.MidPoint) { if (elevationFrom == ElevationFrom.MidPoint) { return(obj.Location.IPointAtParameter(0.5).Z); } if (elevationFrom == ElevationFrom.LowestPoint) { return(BH.Engine.CIH.Query.Points(obj.Location).OrderBy(p => p.Z).First().Z); } if (elevationFrom == ElevationFrom.HighestPoint) { return(BH.Engine.CIH.Query.Points(obj.Location).OrderBy(p => p.Z).Last().Z); } BH.Engine.Reflection.Compute.RecordError($"Could not compute the elevation of a {obj.GetType().Name}."); return(0); }
public static ICurve BoundingBoxCentreline(this IFramingElement element) { ICurve location = element?.Location; if (location == null) { return(null); } Vector normal = null; normal = element.Normal(); if (normal == null) { Engine.Reflection.Compute.RecordError("IFramingElement must have linear location line."); return(null); } Vector tangent = (location.IEndPoint() - location.IStartPoint()).Normalise(); Vector localx = tangent.CrossProduct(normal); if (element.Property is ConstantFramingProperty) { Point centre = (element.Property as ConstantFramingProperty)?.Profile?.Edges?.Bounds()?.Centre(); if (centre == null) { return(null); } Vector sectionTranslate = centre - Point.Origin; return(location.ITranslate(-localx * sectionTranslate.X + normal * sectionTranslate.Y)); } else { Engine.Reflection.Compute.RecordError("Only suitable framing property for the action is ConstantFramingProperty."); return(null); } }
public static Vector Normal(this IFramingElement framingElement) { if (framingElement == null) { BH.Engine.Reflection.Compute.RecordError("Cannot query the normal of a null framing element."); return(null); } double orientationAngle = 0; if (!(framingElement.Property is ConstantFramingProperty)) { Reflection.Compute.RecordWarning("No ConstantFramingProperty found, OrientationAngle set as 0"); } else { orientationAngle = (framingElement.Property as ConstantFramingProperty).OrientationAngle; } return(framingElement.Location.ElementNormal(orientationAngle)); }
public static ICurve ZJustifiedCurve(this IFramingElement element) { if (element == null) { return(null); } string zJustification = element.GetRevitParameterValue("z Justification")?.ToString().ToLower(); if (zJustification == "top") { return(element.TopCentreline()); } else if (zJustification == "bottom") { return(element.BottomCentreline()); } else if (zJustification == "center") { ICurve top = element.TopCentreline(); ICurve bottom = element.BottomCentreline(); Point start = (top.IStartPoint() + bottom.IStartPoint()) * 0.5; Point end = (top.IEndPoint() + bottom.IEndPoint()) * 0.5; return(new Line { Start = start, End = end }); } else if (zJustification == "origin") { return(element.Location); } else { Engine.Reflection.Compute.RecordError("Error extracting z Justification Revit parameter, location curve of the BHoM object has been returned."); return(element.Location); } }
public static IFramingElement Transform(this IFramingElement framingElement, TransformMatrix transform, double tolerance = Tolerance.Distance) { if (!transform.IsRigidTransformation(tolerance)) { BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported."); return(null); } IFramingElement result = framingElement.ShallowClone(); result.Location = result.Location.ITransform(transform); ConstantFramingProperty property = result.Property as ConstantFramingProperty; if (property == null) { BH.Engine.Reflection.Compute.RecordWarning($"Orientation angle of the IFramingElement has not been transformed because its property is not ConstantFramingProperty. BHoM_Guid: {framingElement.BHoM_Guid}"); } else { if (framingElement.Location is Line) { ConstantFramingProperty newProperty = property.ShallowClone(); Vector normalBefore = ((Line)framingElement.Location).ElementNormal(property.OrientationAngle); Vector normalAfter = normalBefore.Transform(transform); newProperty.OrientationAngle = normalAfter.OrientationAngleLinear((Line)result.Location); result.Property = newProperty; } else if (!framingElement.Location.IIsPlanar(tolerance)) { BH.Engine.Reflection.Compute.RecordWarning($"The element's location is a nonlinear, nonplanar curve. Correctness of orientation angle after transform could not be ensured in 100%. BHoM_Guid: {framingElement.BHoM_Guid}"); } } return(result); }
public static double Elevation(this IFramingElement obj) { return(Elevation(obj, ElevationFrom.MidPoint)); }
public static ICurve Geometry(this IFramingElement framingElement) { return(framingElement.Location); }
/***************************************************/ /**** Public methods ****/ /***************************************************/ public static ICurve AdjustedLocationCurveFraming(this IFramingElement framingElement, FamilyInstance familyInstance, RevitSettings settings = null) { settings = settings.DefaultIfNull(); ICurve curve = framingElement?.Location; if (curve == null || (!(curve is NurbsCurve) && curve.ILength() <= settings.DistanceTolerance)) { framingElement.FramingCurveNotFoundWarning(); return(null); } BH.oM.Geometry.Line line = curve as BH.oM.Geometry.Line; if (line == null) { familyInstance.NonLinearFramingOffsetWarning(); return(curve); } Output <Vector, Vector> offsets = familyInstance.FramingOffsetVectors(); Vector startOffset = -offsets.Item1; Vector endOffset = -offsets.Item2; double startOffsetLength = startOffset.Length(); double endOffsetLength = endOffset.Length(); if (startOffsetLength > settings.DistanceTolerance || endOffsetLength > settings.DistanceTolerance) { if ((startOffset - endOffset).Length() > settings.DistanceTolerance) { BH.Engine.Reflection.Compute.RecordError(String.Format("Adjusted location curve of a Revit framing element could not be found because it has non-uniform offsets at ends. Revit ElementId: {0}", familyInstance.Id)); return(null); } Transform transform = familyInstance.GetTotalTransform(); Vector yOffsetStart = new Vector { X = transform.BasisY.X * startOffset.Y, Y = transform.BasisY.Y * startOffset.Y, Z = transform.BasisY.Z * startOffset.Y }; Vector zOffsetStart = new Vector { X = transform.BasisZ.X * startOffset.Z, Y = transform.BasisZ.Y * startOffset.Z, Z = transform.BasisZ.Z * startOffset.Z }; Vector yOffsetEnd = new Vector { X = transform.BasisY.X * endOffset.Y, Y = transform.BasisY.Y * endOffset.Y, Z = transform.BasisY.Z * endOffset.Y }; Vector zOffsetEnd = new Vector { X = transform.BasisZ.X * endOffset.Z, Y = transform.BasisZ.Y * endOffset.Z, Z = transform.BasisZ.Z * endOffset.Z }; line = new BH.oM.Geometry.Line { Start = line.Start.Translate(yOffsetStart + zOffsetStart), End = line.End.Translate(yOffsetEnd + zOffsetEnd) }; } Vector dir = line.Direction(); double startExtension = familyInstance.LookupParameterDouble(BuiltInParameter.START_EXTENSION); if (!double.IsNaN(startExtension)) { line.Start = line.Start + dir * startExtension; } double endExtension = familyInstance.LookupParameterDouble(BuiltInParameter.END_EXTENSION); if (!double.IsNaN(endExtension)) { line.End = line.End - dir * endExtension; } return(line); }
public static List <IFramingElement> ConfigureAgainstSpecifications(HashSet <IFramingElement> objs, List <Specification> specifications) { List <IFramingElement> res = new List <IFramingElement>(); List <string> valueCondPropName = new List <string>(); // Only use specifications that are "applied" Zone Specifications. var appliedZoneSpecs = specifications.Where(s => s.IsAppliedZoneSpec()).ToList(); if (appliedZoneSpecs.Count == 0) { BH.Engine.Reflection.Compute.RecordError($"No Applied Zone Specification found. The input Zone specifications do not have any {nameof(IsInZone)} condition, or do not have their {nameof(IsInZone.ClosedVolumes)} populated."); return(new List <IFramingElement>()); } Dictionary <object, List <IFramingElement> > compatibleObjsPerZone = new Dictionary <object, List <IFramingElement> >(); foreach (var spec in appliedZoneSpecs) { // Remove any IsInZone condition from the specs. // The kit of parts objects are just "archetypes" - not placed in a meaningful location of the model space. Specification specCopy = spec.DeepClone(); specCopy.FilterConditions.RemoveAll(fc => fc is IsInZone); specCopy.CheckConditions.RemoveAll(fc => fc is IsInZone); // The Part of the Kit (object archetype) must be moved in its final location, // so we can make sure that all other conditions can be evaluated on the actual object. // e.g. if there are conditions - that are not IsInZone - that are based on position properties. var allClosedVolumes = spec.FilterConditions.OfType <IsInZone>().SelectMany(c => c.ClosedVolumes); List <Point> closedVolumesCentres = allClosedVolumes.Select(cv => cv.IBounds().Centre()).ToList(); closedVolumesCentres = BH.Engine.Geometry.Compute.CullDuplicates(closedVolumesCentres.ToList()); foreach (var pt in closedVolumesCentres) { foreach (var obj in objs) { compatibleObjsPerZone[pt] = compatibleObjsPerZone.ContainsKey(pt) ? compatibleObjsPerZone[pt] : new List <IFramingElement>(); ICurve geom = obj.Location; var moveVector = BH.Engine.Geometry.Create.Vector(geom.IBounds().Centre(), pt); var movedGeom = BH.Engine.Geometry.Modify.ITranslate(geom, moveVector); IFramingElement objCopy = obj.DeepClone(); objCopy.Location = movedGeom; var specRes = VerifySpecification(new List <object>() { objCopy }, specCopy); if (specRes.PassedObjects.Count != 1) { continue; } valueCondPropName.AddRange(spec.CheckConditions.OfType <IValueCondition>().Select(c => c.PropertyName)); compatibleObjsPerZone[pt].Add(objCopy); } } } List <IFramingElement> result = new List <IFramingElement>(); foreach (var kv in compatibleObjsPerZone) { var ordered = kv.Value.OrderBy(v => v.ValueFromSource("Property.IAverageProfileArea")).ToList(); if (ordered.FirstOrDefault() != null) { result.Add(ordered.FirstOrDefault()); } } return(result); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ // Configure to Order workflow. public static List <IFramingElement> ConfigureAgainstSpecifications(HashSet <IFramingElement> objs, List <Specification> specifications, bool sortDirection = true) { if (!previousSet.Any()) { previousSet = objs; } if (!previousSet.Intersect(objs).Any()) { return(previousConfig); } // Override hack. previousConfig = ConfigureAgainstSpecifications(objs, specifications); return(previousConfig); List <IFramingElement> result = new List <IFramingElement>(); List <Specification> compatibleSpecs = new List <Specification>(); var compatibleObject = CompatibleObjects(objs, specifications, out compatibleSpecs, 1, sortDirection).FirstOrDefault(); if (compatibleObject == null) { return(new List <IFramingElement>()); } var appliedZoneSpecs = specifications.Where(s => s.IsAppliedZoneSpec()); List <Point> allDistinctClosedVolumeCentres = new List <Point>(); foreach (var spec in compatibleSpecs) { var allClosedVolumes = spec.FilterConditions.OfType <IsInZone>().SelectMany(c => c.ClosedVolumes); List <Point> closedVolumesCentres = allClosedVolumes.Select(cv => cv.IBounds().Centre()).ToList(); closedVolumesCentres = BH.Engine.Geometry.Compute.CullDuplicates(closedVolumesCentres.ToList()); foreach (var pt in closedVolumesCentres) { allDistinctClosedVolumeCentres.Add(pt); } } allDistinctClosedVolumeCentres = BH.Engine.Geometry.Compute.CullDuplicates(allDistinctClosedVolumeCentres); foreach (var pt in allDistinctClosedVolumeCentres) { // The object satisfied this spec. // Move the object into the "location of this spec". ICurve geom = compatibleObject.Location; var moveVector = BH.Engine.Geometry.Create.Vector(geom.IBounds().Centre(), pt); var movedGeom = BH.Engine.Geometry.Modify.ITranslate(geom, moveVector); IFramingElement objCopy = compatibleObject.DeepClone(); objCopy.Location = movedGeom; result.Add(objCopy); } return(result.Distinct().ToList()); }
public static List <IFramingElement> CompatibleObjects(HashSet <IFramingElement> objects, List <Specification> specifications, out List <Specification> compatibleSpecs, int limit = 1, bool sortDirection = true) { List <IFramingElement> res = new List <IFramingElement>(); compatibleSpecs = new List <Specification>(); List <string> valueCondPropName = new List <string>(); // Only use specifications that are "applied" Zone Specifications. var appliedZoneSpecs = specifications.Where(s => s.IsAppliedZoneSpec()).ToList(); if (appliedZoneSpecs.Count == 0) { BH.Engine.Reflection.Compute.RecordError($"No Applied Zone Specification found. The input Zone specifications do not have any {nameof(IsInZone)} condition, or do not have their {nameof(IsInZone.ClosedVolumes)} populated."); return(new List <IFramingElement>()); } foreach (var obj in objects) { foreach (var spec in appliedZoneSpecs) { // Remove any IsInZone condition from the specs. // The kit of parts objects are just "archetypes" - not placed in a meaningful location of the model space. Specification specCopy = spec.DeepClone(); specCopy.FilterConditions.RemoveAll(fc => fc is IsInZone); specCopy.CheckConditions.RemoveAll(fc => fc is IsInZone); // The Part of the Kit (object archetype) must be moved in its final location, // so we can make sure that all other conditions can be evaluated on the actual object. // e.g. if there are conditions - that are not IsInZone - that are based on position properties. var allClosedVolumes = spec.FilterConditions.OfType <IsInZone>().SelectMany(c => c.ClosedVolumes); List <Point> closedVolumesCentres = allClosedVolumes.Select(cv => cv.IBounds().Centre()).ToList(); closedVolumesCentres = BH.Engine.Geometry.Compute.CullDuplicates(closedVolumesCentres.ToList()); foreach (var pt in closedVolumesCentres) { ICurve geom = obj.Location; var moveVector = BH.Engine.Geometry.Create.Vector(geom.IBounds().Centre(), pt); var movedGeom = BH.Engine.Geometry.Modify.ITranslate(geom, moveVector); IFramingElement objCopy = obj.DeepClone(); objCopy.Location = movedGeom; var specRes = VerifySpecification(new List <object>() { objCopy }, specCopy); if (specRes.PassedObjects.Count != 1) { continue; } valueCondPropName.AddRange(spec.CheckConditions.OfType <IValueCondition>().Select(c => c.PropertyName)); res.Add(obj); compatibleSpecs.Add(spec); } } } res = res.Distinct().ToList(); valueCondPropName = valueCondPropName.Distinct().ToList(); compatibleSpecs = compatibleSpecs.Distinct().ToList(); if (valueCondPropName.Count == 1) { res = res.OrderBy(obj => obj.ValueFromSource(valueCondPropName.First())).ToList(); } if (!sortDirection) { res.Reverse(); } if (res.Count() == 0) { BH.Engine.Reflection.Compute.RecordWarning("No compatible object found."); return(new List <IFramingElement>()); } return(res.Take(limit).ToList()); }
/***************************************************/ public static FamilyInstance ToRevitFamilyInstance(this IFramingElement framingElement, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null) { if (framingElement == null || document == null) { return(null); } FamilyInstance familyInstance = refObjects.GetValue <FamilyInstance>(document, framingElement.BHoM_Guid); if (familyInstance != null) { return(familyInstance); } settings = settings.DefaultIfNull(); if (framingElement.Location == null) { BH.Engine.Reflection.Compute.RecordError(String.Format("Revit element could not be created because the driving curve of a BHoM object is null. BHoM_Guid: {0}", framingElement.BHoM_Guid)); return(null); } if (!framingElement.Location.IIsPlanar()) { BH.Engine.Reflection.Compute.RecordError(string.Format("Revit framing does only support planar curves, element could not be created. BHoM_Guid: {0}", framingElement.BHoM_Guid)); return(null); } Curve revitCurve = framingElement.Location.IToRevit(); if (revitCurve == null) { BH.Engine.Reflection.Compute.RecordError(string.Format("Revit element could not be created because of curve conversion issues. BHoM_Guid: {0}", framingElement.BHoM_Guid)); return(null); } Level level = document.LevelBelow(framingElement.Location, settings); FamilySymbol familySymbol = framingElement.Property.ToRevitElementType(document, framingElement.BuiltInCategories(document), settings, refObjects); if (familySymbol == null) { familySymbol = framingElement.ElementType(document, settings) as FamilySymbol; } if (familySymbol == null) { Compute.ElementTypeNotFoundWarning(framingElement); return(null); } FamilyPlacementType familyPlacementType = familySymbol.Family.FamilyPlacementType; if (familyPlacementType != FamilyPlacementType.CurveBased && familyPlacementType != FamilyPlacementType.CurveBasedDetail && familyPlacementType != FamilyPlacementType.CurveDrivenStructural && familyPlacementType != FamilyPlacementType.TwoLevelsBased) { Compute.InvalidFamilyPlacementTypeError(framingElement, familySymbol); return(null); } if (framingElement is Beam) { familyInstance = document.Create.NewFamilyInstance(revitCurve, familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.Beam); } else if (framingElement is Bracing || framingElement is Cable) { familyInstance = document.Create.NewFamilyInstance(revitCurve, familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.Brace); } else { familyInstance = document.Create.NewFamilyInstance(revitCurve, familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.UnknownFraming); } document.Regenerate(); familyInstance.CheckIfNullPush(framingElement); if (familyInstance == null) { return(null); } oM.Physical.FramingProperties.ConstantFramingProperty barProperty = framingElement.Property as oM.Physical.FramingProperties.ConstantFramingProperty; if (barProperty != null) { //TODO: if the material does not get assigned an error should be thrown? if (barProperty.Material != null) { Material material = document.GetElement(new ElementId(BH.Engine.Adapters.Revit.Query.ElementId(barProperty.Material))) as Material; if (material != null) { Parameter param = familyInstance.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM); if (param != null && param.HasValue && !param.IsReadOnly) { familyInstance.StructuralMaterialId = material.Id; } else { BH.Engine.Reflection.Compute.RecordWarning(string.Format("The BHoM material has been correctly converted, but the property could not be assigned to the Revit element. ElementId: {0}", familyInstance.Id)); } } } } //Set the insertion point to centroid. Parameter zJustification = familyInstance.get_Parameter(BuiltInParameter.Z_JUSTIFICATION); if (zJustification != null && !zJustification.IsReadOnly) { zJustification.Set((int)Autodesk.Revit.DB.Structure.ZJustification.Origin); } familyInstance.CopyParameters(framingElement, settings); familyInstance.SetLocation(framingElement, settings); if (familyInstance.StructuralMaterialType != StructuralMaterialType.Concrete && familyInstance.StructuralMaterialType != StructuralMaterialType.PrecastConcrete) { StructuralFramingUtils.DisallowJoinAtEnd(familyInstance, 0); StructuralFramingUtils.DisallowJoinAtEnd(familyInstance, 1); } refObjects.AddOrReplace(framingElement, familyInstance); return(familyInstance); }
/***************************************************/ /**** Interface methods ****/ /***************************************************/ public static FamilyInstance IToRevitFamilyInstance(this IFramingElement framingElement, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null) { return(ToRevitFamilyInstance(framingElement as dynamic, document, settings, refObjects)); }