/***************************************************/ 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 Space SpaceFromRevit(this EnergyAnalysisSpace energyAnalysisSpace, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { if (energyAnalysisSpace == null) { return(new Space()); } settings = settings.DefaultIfNull(); Space space = refObjects.GetValue <Space>(energyAnalysisSpace.Id.IntegerValue); if (space != null) { return(space); } SpatialElement spatialElement = energyAnalysisSpace.Document.Element(energyAnalysisSpace.CADObjectUniqueId) as SpatialElement; if (spatialElement == null) { return(space); //If we can't get data from it let's not waste our time } space = new Space(); space.Name = Query.Name(spatialElement); Polyline pline = energyAnalysisSpace.GetBoundary().Select(x => x.FromRevit()).ToList().Join().FirstOrDefault(); if (pline != null) { space.Location = pline.Centroid(); space.Perimeter = pline; } else if (spatialElement != null && spatialElement.Location != null) { space.Location = (spatialElement.Location as LocationPoint).FromRevit(); } //Set ExtendedProperties OriginContextFragment originContext = new OriginContextFragment() { ElementID = spatialElement.Id.IntegerValue.ToString(), TypeName = Query.Name(spatialElement) }; originContext.SetProperties(energyAnalysisSpace, settings.ParameterSettings); originContext.SetProperties(spatialElement, settings.ParameterSettings); space.AddFragment(originContext); SpaceAnalyticalFragment spaceAnalytical = new SpaceAnalyticalFragment(); spaceAnalytical.SetProperties(energyAnalysisSpace, settings.ParameterSettings); spaceAnalytical.SetProperties(spatialElement, settings.ParameterSettings); space.AddFragment(spaceAnalytical); SpaceContextFragment spaceContext = new SpaceContextFragment(); List <string> connectedElements = new List <string>(); foreach (EnergyAnalysisSurface energyAnalysisSurface in energyAnalysisSpace.GetAnalyticalSurfaces()) { connectedElements.Add(energyAnalysisSurface.CADObjectUniqueId); } spaceContext.ConnectedElements = connectedElements; spaceContext.SetProperties(energyAnalysisSpace, settings.ParameterSettings); spaceContext.SetProperties(spatialElement, settings.ParameterSettings); space.AddFragment(spaceContext); //Set identifiers, parameters & custom data space.SetIdentifiers(spatialElement); space.CopyParameters(spatialElement, settings.ParameterSettings); space.SetProperties(spatialElement, settings.ParameterSettings); space.SetProperties(energyAnalysisSpace, settings.ParameterSettings); refObjects.AddOrReplace(energyAnalysisSpace.Id, space); return(space); }