Ejemplo n.º 1
0
        public static Space ToSpeckle(this Autodesk.Revit.DB.Mechanical.Space mySpace)
        {
            var speckleSpace = new SpeckleElementsClasses.Space();

            //Name & number
            speckleSpace.spaceName   = mySpace.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ROOM_NAME).AsString();
            speckleSpace.spaceNumber = mySpace.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ROOM_NUMBER).AsString();

            //Location
            var locPt = ((Autodesk.Revit.DB.LocationPoint)mySpace.Location).Point;

            speckleSpace.spaceLocation  = new SpecklePoint(locPt.X / Scale, locPt.Y / Scale, locPt.Z / Scale);
            speckleSpace.levelElementId = mySpace.LevelId.IntegerValue.ToString();
            speckleSpace.phaseElementId = mySpace.GetParameters("Phase Id").FirstOrDefault().AsElementId().ToString();

            //3d geometry
            (speckleSpace.Faces, speckleSpace.Vertices) = GetFaceVertexArrayFromElement(mySpace);

            //2d boundary curve
            var seg         = mySpace.GetBoundarySegments(new Autodesk.Revit.DB.SpatialElementBoundaryOptions());
            var myPolyCurve = new SpecklePolycurve()
            {
                Segments = new List <SpeckleCore.SpeckleObject>()
            };

            foreach (BoundarySegment segment in seg[0])
            {
                var crv       = segment.GetCurve();
                var converted = SpeckleCore.Converter.Serialise(crv);
                myPolyCurve.Segments.Add(converted as SpeckleObject);
            }
            speckleSpace.baseCurve = myPolyCurve;

            //parameters
            speckleSpace.parameters = GetElementParams(mySpace);

            //try get type parameters
            if (mySpace.IsValidType(mySpace.GetTypeId()))
            {
                speckleSpace.typeParameters = GetElementTypeParams(mySpace);
            }

            //global parameters
            speckleSpace.ApplicationId = mySpace.UniqueId;
            speckleSpace.elementId     = mySpace.Id.ToString();
            speckleSpace.GenerateHash();

            return(speckleSpace);
        }
Ejemplo n.º 2
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);
        }