/***************************************************/ public static Space SpaceFromRevit(this SpatialElement spatialElement, SpatialElementGeometryCalculator spatialElementGeometryCalculator, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { if (spatialElement == null || spatialElementGeometryCalculator == null) { return(new Space()); } settings = settings.DefaultIfNull(); Space space = refObjects.GetValue <Space>(spatialElement.Id); if (space != null) { return(space); } //Create the Space space = new Space(); space.Name = Query.Name(spatialElement); PolyCurve pcurve = spatialElement.Perimeter(settings).FirstOrDefault(); if (pcurve != null) { space.Location = pcurve.Centroid(); space.Perimeter = pcurve; } else if (spatialElement.Location != null && spatialElement.Location is LocationPoint) { space.Location = ((LocationPoint)spatialElement.Location).FromRevit(); } //Set ExtendedProperties OriginContextFragment originContext = new OriginContextFragment() { ElementID = spatialElement.Id.IntegerValue.ToString(), TypeName = Query.Name(spatialElement) }; originContext.SetProperties(spatialElement, settings.ParameterSettings); space.AddFragment(originContext); SpaceAnalyticalFragment spaceAnalytical = new SpaceAnalyticalFragment(); spaceAnalytical.SetProperties(spatialElement, settings.ParameterSettings); space.AddFragment(spaceAnalytical); SpaceContextFragment spaceContext = new SpaceContextFragment(); spaceContext.SetProperties(spatialElement, settings.ParameterSettings); //TODO: Implement ConnectedElements space.AddFragment(spaceContext); //Set identifiers, parameters & custom data space.SetIdentifiers(spatialElement); space.CopyParameters(spatialElement, settings.ParameterSettings); space.SetProperties(spatialElement, settings.ParameterSettings); refObjects.AddOrReplace(spatialElement.Id, space); return(space); }
public static Point Centroid(this PolyCurve curve) { return(curve.Centroid(Tolerance.Distance)); }