예제 #1
0
        public static List <Autodesk.Revit.DB.Mechanical.Space> ToRevit(this AdjacencyCluster adjacencyCluster, Zone zone, Document document, ConvertSettings convertSettings)
        {
            if (adjacencyCluster == null || zone == null)
            {
                return(null);
            }

            List <Autodesk.Revit.DB.Mechanical.Space> result = convertSettings?.GetObjects <Autodesk.Revit.DB.Mechanical.Space>(zone.Guid);

            if (result != null)
            {
                return(result);
            }

            Zone zone_Temp = adjacencyCluster.GetObject <Zone>(zone.Guid);

            if (zone_Temp == null)
            {
                zone_Temp = zone;
            }

            if (convertSettings.ConvertParameters)
            {
                List <Space> spaces = adjacencyCluster.GetSpaces(zone_Temp);
                if (spaces != null)
                {
                    List <Autodesk.Revit.DB.Mechanical.Space> spaces_Revit = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_MEPSpaces).Cast <Autodesk.Revit.DB.Mechanical.Space>().ToList();

                    foreach (Space space in spaces)
                    {
                        Autodesk.Revit.DB.Mechanical.Space space_Revit = Core.Revit.Query.Element <Autodesk.Revit.DB.Mechanical.Space>(document, space);
                        if (space_Revit == null)
                        {
                            string name = space.Name;
                            if (name != null)
                            {
                                space_Revit = spaces_Revit?.Find(x => x.get_Parameter(BuiltInParameter.ROOM_NAME)?.AsString() == name);
                            }
                        }

                        if (space_Revit == null)
                        {
                            continue;
                        }

                        Core.Revit.Modify.SetValues(space_Revit, zone_Temp);
                        Core.Revit.Modify.SetValues(space_Revit, zone_Temp, ActiveSetting.Setting);
                    }
                }
            }

            convertSettings?.Add(zone.Guid, result);

            return(result);
        }
예제 #2
0
        public static List <Autodesk.Revit.DB.Mechanical.Space> ToRevit(this AdjacencyCluster adjacencyCluster, ZoneSimulationResult zoneSimulationResult, Document document, ConvertSettings convertSettings)
        {
            if (adjacencyCluster == null || zoneSimulationResult == null)
            {
                return(null);
            }

            List <Autodesk.Revit.DB.Mechanical.Space> result = convertSettings?.GetObjects <Autodesk.Revit.DB.Mechanical.Space>(zoneSimulationResult.Guid);

            if (result != null)
            {
                return(result);
            }

            ZoneSimulationResult zoneSimulationResult_Temp = adjacencyCluster.GetObject <ZoneSimulationResult>(zoneSimulationResult.Guid);

            if (zoneSimulationResult_Temp == null)
            {
                zoneSimulationResult_Temp = zoneSimulationResult;
            }

            List <Zone> zones = adjacencyCluster.GetRelatedObjects <Zone>(zoneSimulationResult_Temp);

            if (zones != null && zones.Count != 0)
            {
                if (convertSettings.ConvertParameters)
                {
                    foreach (Zone zone in zones)
                    {
                        List <Space> spaces = adjacencyCluster.GetSpaces(zone);
                        if (spaces != null)
                        {
                            ZoneType zoneType = zone.ZoneType();
                            if (zoneType == ZoneType.Undefined)
                            {
                                continue;
                            }

                            List <Autodesk.Revit.DB.Mechanical.Space> spaces_Revit = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_MEPSpaces).Cast <Autodesk.Revit.DB.Mechanical.Space>().ToList();

                            foreach (Space space_SAM in spaces)
                            {
                                Autodesk.Revit.DB.Mechanical.Space space_Revit = Core.Revit.Query.Element <Autodesk.Revit.DB.Mechanical.Space>(document, zoneSimulationResult_Temp);

                                if (space_Revit == null)
                                {
                                    space_Revit = Core.Revit.Query.Element <Autodesk.Revit.DB.Mechanical.Space>(document, space_SAM);
                                }

                                if (space_Revit == null)
                                {
                                    space_Revit = spaces_Revit?.Find(x => x.get_Parameter(BuiltInParameter.ROOM_NAME)?.AsString() == space_SAM.Name);
                                }

                                if (space_Revit == null)
                                {
                                    space_Revit = spaces_Revit?.Find(x => space_SAM.Name.EndsWith(x.get_Parameter(BuiltInParameter.ROOM_NAME)?.AsString()) && space_SAM.Name.StartsWith(x.get_Parameter(BuiltInParameter.ROOM_NUMBER)?.AsString()));
                                }

                                if (space_Revit == null)
                                {
                                    continue;
                                }

                                Core.Revit.Modify.SetValues(space_Revit, zoneSimulationResult);
                                Core.Revit.Modify.SetValues(space_Revit, zoneSimulationResult, ActiveSetting.Setting);

                                Modify.SetValues(space_Revit, zoneSimulationResult, ActiveSetting.Setting, zoneType, convertSettings?.GetParameters());
                            }
                        }
                    }
                }
            }

            convertSettings?.Add(zoneSimulationResult.Guid, result);

            return(result);
        }
예제 #3
0
        public static List <Autodesk.Revit.DB.Mechanical.Space> ToRevit(this AdjacencyCluster adjacencyCluster, Zone zone, Document document, ConvertSettings convertSettings)
        {
            if (adjacencyCluster == null || zone == null)
            {
                return(null);
            }

            List <Autodesk.Revit.DB.Mechanical.Space> result = convertSettings?.GetObjects <Autodesk.Revit.DB.Mechanical.Space>(zone.Guid);

            if (result != null)
            {
                return(result);
            }

            Zone zone_Temp = adjacencyCluster.GetObject <Zone>(zone.Guid);

            if (zone_Temp == null)
            {
                zone_Temp = zone;
            }

            if (convertSettings.ConvertParameters)
            {
                string zoneParameterName = Query.ZoneParameterName(zone);

                ZoneType zoneType = zone.ZoneType();

                List <Space> spaces = adjacencyCluster.GetSpaces(zone_Temp);
                if (spaces != null)
                {
                    List <Autodesk.Revit.DB.Mechanical.Space> spaces_Revit = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_MEPSpaces).Cast <Autodesk.Revit.DB.Mechanical.Space>().ToList();

                    foreach (Space space_SAM in spaces)
                    {
                        Autodesk.Revit.DB.Mechanical.Space space_Revit = Core.Revit.Query.Element <Autodesk.Revit.DB.Mechanical.Space>(document, zone);

                        if (space_Revit == null)
                        {
                            space_Revit = Core.Revit.Query.Element <Autodesk.Revit.DB.Mechanical.Space>(document, space_SAM);
                        }

                        if (space_Revit == null)
                        {
                            space_Revit = spaces_Revit?.Find(x => x.get_Parameter(BuiltInParameter.ROOM_NAME)?.AsString() == space_SAM.Name);
                        }

                        if (space_Revit == null)
                        {
                            space_Revit = spaces_Revit?.Find(x => space_SAM.Name.EndsWith(x.get_Parameter(BuiltInParameter.ROOM_NAME)?.AsString()) && space_SAM.Name.StartsWith(x.get_Parameter(BuiltInParameter.ROOM_NUMBER)?.AsString()));
                        }


                        if (space_Revit == null)
                        {
                            continue;
                        }

                        if (!string.IsNullOrWhiteSpace(zoneParameterName))
                        {
                            IEnumerable <Parameter> parameters = space_Revit.GetParameters(zoneParameterName);
                            if (parameters != null)
                            {
                                foreach (Parameter parameter in parameters)
                                {
                                    if (parameter == null || parameter.IsReadOnly || parameter.StorageType != StorageType.String)
                                    {
                                        continue;
                                    }

                                    parameter.Set(zone.Name);
                                }
                            }
                        }

                        Core.Revit.Modify.SetValues(space_Revit, zone_Temp);
                        Core.Revit.Modify.SetValues(space_Revit, zone_Temp, ActiveSetting.Setting);

                        if (zoneType != ZoneType.Undefined)
                        {
                            Modify.SetValues(space_Revit, zone_Temp, ActiveSetting.Setting, zoneType, convertSettings?.GetParameters());
                        }
                    }
                }
            }

            convertSettings?.Add(zone.Guid, result);

            return(result);
        }