示例#1
0
        public static Level ToSAM(this Autodesk.Revit.DB.Level level, ConvertSettings convertSettings)
        {
            if (level == null)
            {
                return(null);
            }

            Document document = level.Document;

            Level result = convertSettings?.GetObject <Level>(level.Id);

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

            double elevation = Query.Elevation(level);

            result = new Level(level.Name, elevation);
            result.UpdateParameterSets(level, ActiveSetting.Setting.GetValue <Core.TypeMap>(ActiveSetting.Name.ParameterMap));
            //result.Add(Core.Revit.Query.ParameterSet(level));

            convertSettings?.Add(level.Id, result);

            return(result);
        }
示例#2
0
        public static RevitType ToSAM(this ElementType elementType, ConvertSettings convertSettings)
        {
            if (elementType == null)
            {
                return(null);
            }

            RevitType result = convertSettings?.GetObject <RevitType>(elementType.Id);

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

            switch (elementType.Category.CategoryType)
            {
            case CategoryType.AnalyticalModel:
            case CategoryType.Model:
                result = new RevitType3D(elementType.Name);
                break;

            case CategoryType.Annotation:
                result = new RevitType2D(elementType.Name);
                break;
            }

            if (result != null)
            {
                result.UpdateParameterSets(elementType, ActiveSetting.Setting.GetValue <TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));
                convertSettings?.Add(elementType.Id, result);
            }

            return(result);
        }
示例#3
0
        public static DesignOption ToSAM(this Autodesk.Revit.DB.DesignOption designOption, ConvertSettings convertSettings)
        {
            if (designOption == null)
            {
                return(null);
            }

            DesignOption result = convertSettings?.GetObject <DesignOption>(designOption.Id);

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

            result = new DesignOption(designOption.Name, designOption.IsPrimary);

            result.UpdateParameterSets(designOption, ActiveSetting.Setting.GetValue <TypeMap>(ActiveSetting.Name.ParameterMap));

            if (result != null)
            {
                convertSettings?.Add(designOption.Id, result);
            }

            return(result);
        }
示例#4
0
        public static IOpening ToSAM_Opening(this EnergyAnalysisOpening energyAnalysisOpening, ConvertSettings convertSettings)
        {
            if (energyAnalysisOpening == null)
            {
                return(null);
            }

            IOpening result = convertSettings?.GetObject <IOpening>(energyAnalysisOpening.Id);

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

            Polygon3D polygon3D = energyAnalysisOpening.GetPolyloop().ToSAM();

            if (polygon3D == null)
            {
                return(null);
            }

            FamilyInstance familyInstance = Core.Revit.Query.Element(energyAnalysisOpening) as FamilyInstance;

            if (familyInstance == null)
            {
                return(null);
            }

            if (Core.Revit.Query.Simplified(familyInstance))
            {
                result = Core.Revit.Query.IJSAMObjects <IOpening>(familyInstance)?.FirstOrDefault();
                if (result != null)
                {
                    return(result);
                }
            }

            OpeningType openingType = ToSAM_OpeningType(familyInstance.Symbol, convertSettings);

            Point3D point3D_Location = Geometry.Revit.Query.LocationPoint3D(familyInstance);

            if (point3D_Location == null)
            {
                return(null);
            }

            Face3D face3D = new Face3D(Geometry.Spatial.Create.IClosedPlanar3D(polygon3D, point3D_Location));

            if (face3D == null)
            {
                return(null);
            }

            result = Analytical.Create.Opening(openingType, face3D);
            result.UpdateParameterSets(familyInstance);

            convertSettings?.Add(energyAnalysisOpening.Id, result);

            return(result);
        }
        public static ProjectInfo ToRevit(this AdjacencyClusterSimulationResult adjacencyClusterSimulationResult, Document document, ConvertSettings convertSettings)
        {
            if (adjacencyClusterSimulationResult == null || document == null)
            {
                return(null);
            }

            ProjectInfo result = convertSettings?.GetObject <ProjectInfo>(adjacencyClusterSimulationResult.Guid);

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

            result = document.ProjectInformation;

            if (convertSettings.ConvertParameters)
            {
                if (result != null)
                {
                    Core.Revit.Modify.SetValues(result, adjacencyClusterSimulationResult);
                    Core.Revit.Modify.SetValues(result, adjacencyClusterSimulationResult, ActiveSetting.Setting);
                    Modify.SetValues(result, adjacencyClusterSimulationResult, ActiveSetting.Setting, adjacencyClusterSimulationResult.LoadType());
                }
            }

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

            return(result);
        }
示例#6
0
        public static Aperture ToSAM(this EnergyAnalysisOpening energyAnalysisOpening, ConvertSettings convertSettings)
        {
            if (energyAnalysisOpening == null)
            {
                return(null);
            }

            Aperture result = convertSettings?.GetObject <Aperture>(energyAnalysisOpening.Id);

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

            Polygon3D polygon3D = energyAnalysisOpening.GetPolyloop().ToSAM();

            if (polygon3D == null)
            {
                return(null);
            }

            FamilyInstance familyInstance = Core.Revit.Query.Element(energyAnalysisOpening) as FamilyInstance;

            if (familyInstance == null)
            {
                return(new Aperture(null, polygon3D));
            }

            if (Core.Revit.Query.Simplified(familyInstance))
            {
                result = Core.Revit.Query.IJSAMObjects <Aperture>(familyInstance)?.FirstOrDefault();
                if (result != null)
                {
                    return(result);
                }
            }

            ApertureConstruction apertureConstruction = ToSAM_ApertureConstruction(familyInstance, convertSettings);

            Point3D point3D_Location = Geometry.Revit.Query.LocationPoint3D(familyInstance);

            if (point3D_Location == null)
            {
                return(null);
            }

            result = new Aperture(apertureConstruction, polygon3D, point3D_Location);
            result.UpdateParameterSets(energyAnalysisOpening, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));
            //result.UpdateParameterSets(familyInstance, ActiveSetting.Setting.GetValue<Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));
            //result.Add(Core.Revit.Query.ParameterSet(familyInstance));

            convertSettings?.Add(energyAnalysisOpening.Id, result);

            return(result);
        }
示例#7
0
        public static Autodesk.Revit.DB.Mechanical.Space ToRevit(this Space space, Document document, ConvertSettings convertSettings)
        {
            if (space == null)
            {
                return(null);
            }

            Autodesk.Revit.DB.Mechanical.Space result = convertSettings?.GetObject <Autodesk.Revit.DB.Mechanical.Space>(space.Guid);
            if (result != null)
            {
                return(result);
            }

            if (!convertSettings.RemoveExisting)
            {
                result = Core.Revit.Query.Element <Autodesk.Revit.DB.Mechanical.Space>(document, space);
            }

            if (result == null)
            {
                double lowElevation = Query.LowElevation(space);
                if (double.IsNaN(lowElevation))
                {
                    return(null);
                }

                Level level = Geometry.Revit.Query.LowLevel(document, lowElevation);
                if (level == null)
                {
                    return(null);
                }

                result = document.Create.NewSpace(level, new UV(UnitUtils.ConvertToInternalUnits(space.Location.X, DisplayUnitType.DUT_METERS), UnitUtils.ConvertToInternalUnits(space.Location.Y, DisplayUnitType.DUT_METERS)));
            }

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

            result.get_Parameter(BuiltInParameter.ROOM_NAME).Set(space.Name);

            if (convertSettings.ConvertParameters)
            {
                Core.Revit.Modify.SetValues(result, space);
                Core.Revit.Modify.SetValues(result, space, ActiveSetting.Setting);

                Core.Revit.Modify.SetJson(result, space.ToJObject()?.ToString());
            }

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

            return(result);
        }
示例#8
0
        public static IRevitInstance ToSAM(this FamilyInstance familyInstance, ConvertSettings convertSettings)
        {
            if (familyInstance == null || !familyInstance.IsValidObject)
            {
                return(null);
            }

            IRevitInstance result = convertSettings?.GetObject <IRevitInstance>(familyInstance.Id);

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

            Document document = familyInstance.Document;

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

            ElementType elementType = document.GetElement(familyInstance.GetTypeId()) as ElementType;

            if (elementType == null)
            {
                return(null);
            }

            RevitType revitType = elementType.ToSAM(convertSettings);

            if (revitType == null)
            {
                return(null);
            }

            if (revitType is RevitType3D)
            {
                result = new RevitInstance3D((RevitType3D)revitType, familyInstance.ToSAM_Geometries <Spatial.ISAMGeometry3D>());
            }
            else if (revitType is RevitType2D)
            {
                result = new RevitInstance2D((RevitType2D)revitType, familyInstance.ToSAM_Geometries <Planar.ISAMGeometry2D>());
            }

            if (result != null)
            {
                result.UpdateParameterSets(familyInstance, ActiveSetting.Setting.GetValue <TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));
                convertSettings?.Add(familyInstance.Id, result);
            }

            return(result);
        }
示例#9
0
        public static HostPartitionType ToSAM_HostPartitionType(this HostObjAttributes hostObjAttributes, ConvertSettings convertSettings)
        {
            if (hostObjAttributes == null)
            {
                return(null);
            }

            HostPartitionType result = convertSettings?.GetObject <HostPartitionType>(hostObjAttributes.Id);

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

            string name = hostObjAttributes.Name;

            List <MaterialLayer> materialLayers = Architectural.Revit.Create.MaterialLayers(hostObjAttributes.Document, hostObjAttributes.GetCompoundStructure());

            if (materialLayers == null)
            {
                return(null);
            }

            if (hostObjAttributes is Autodesk.Revit.DB.WallType)
            {
                result = new WallType(name);
            }
            else if (hostObjAttributes is Autodesk.Revit.DB.RoofType)
            {
                result = new RoofType(name);
            }
            else if (hostObjAttributes is Autodesk.Revit.DB.FloorType)
            {
                result = new FloorType(name);
            }

            CompoundStructure compoundStructure = hostObjAttributes.GetCompoundStructure();

            if (compoundStructure != null)
            {
                compoundStructure.GetLayers();
            }

            if (result != null)
            {
                result.UpdateParameterSets(hostObjAttributes);
                convertSettings?.Add(hostObjAttributes.Id, result);
            }

            return(result);
        }
示例#10
0
        public static InternalCondition ToSAM_InternalCondition(this SpatialElement spatialElement, ConvertSettings convertSettings)
        {
            if (spatialElement == null)
            {
                return(null);
            }

            InternalCondition result = convertSettings?.GetObject <InternalCondition>(spatialElement.Id);

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

            string name = null;

            Core.TypeMap typeMap = ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap);
            if (typeMap != null)
            {
                string parameterName = typeMap.GetName(typeof(InternalCondition), typeof(Autodesk.Revit.DB.Mechanical.Space), "Name", 2);
                if (!string.IsNullOrWhiteSpace(parameterName))
                {
                    Parameter parameter = spatialElement.GetParameters(parameterName)?.ToList().Find(x => x.StorageType == StorageType.String);
                    if (parameter != null)
                    {
                        name = parameter.AsString();
                    }
                }

                if (string.IsNullOrWhiteSpace(name))
                {
                    name = Core.Revit.Query.Name(spatialElement);
                }

                if (string.IsNullOrWhiteSpace(name))
                {
                    name = spatialElement.Name;
                }
            }

            result = new InternalCondition(name);

            result.UpdateParameterSets(spatialElement, typeMap, null, null, false);

            convertSettings?.Add(spatialElement.Id, result);

            return(result);
        }
示例#11
0
        public static RevitInstance3D ToSAM(this WallSweep wallSweep, ConvertSettings convertSettings)
        {
            if (wallSweep == null || !wallSweep.IsValidObject)
            {
                return(null);
            }

            RevitInstance3D result = convertSettings?.GetObject <RevitInstance3D>(wallSweep.Id);

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

            Document document = wallSweep.Document;

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

            ElementType elementType = document.GetElement(wallSweep.GetTypeId()) as ElementType;

            if (elementType == null)
            {
                return(null);
            }

            RevitType3D revitType3D = elementType.ToSAM(convertSettings) as RevitType3D;

            if (revitType3D == null)
            {
                return(null);
            }

            result = new RevitInstance3D(revitType3D, wallSweep.ToSAM_Geometries <Spatial.ISAMGeometry3D>());

            if (result != null)
            {
                result.UpdateParameterSets(elementType, ActiveSetting.Setting.GetValue <TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));
                convertSettings?.Add(elementType.Id, result);
            }

            return(result);
        }
示例#12
0
        public static Construction ToSAM_Construction(this ElementType elementType, ConvertSettings convertSettings)
        {
            if (elementType == null || elementType.Category == null)
            {
                return(null);
            }

            if ((BuiltInCategory)elementType.Category.Id.IntegerValue != BuiltInCategory.OST_Cornices)
            {
                return(null);
            }

            Construction result = convertSettings?.GetObject <Construction>(elementType.Id);

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

            PanelType panelType = PanelType.Wall;

            string name = elementType.Name;

            Construction construction = Analytical.Query.DefaultConstruction(panelType);

            if (construction != null && (name.Equals(construction.Name) || name.Equals(construction.UniqueName())))
            {
                result = new Construction(construction);
            }
            else
            {
                result = new Construction(elementType.Name);
            }

            result.UpdateParameterSets(elementType, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));
            result.SetValue(ConstructionParameter.DefaultPanelType, panelType.Text());

            convertSettings?.Add(elementType.Id, result);
            return(result);
        }
示例#13
0
        public static TagType ToSAM(this SpaceTagType spaceTagType, ConvertSettings convertSettings)
        {
            if (spaceTagType == null)
            {
                return(null);
            }

            TagType result = convertSettings?.GetObject <TagType>(spaceTagType.Id);

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

            result = new TagType(spaceTagType.Name);
            if (result != null)
            {
                Modify.SetValues(spaceTagType, result);
                result.SetValue(ElementParameter.RevitId, Query.IntegerId(spaceTagType));
                convertSettings?.Add(spaceTagType.Id, result);
            }

            return(result);
        }
示例#14
0
        public static TagType ToSAM_TagType(this FamilySymbol familySymbol, ConvertSettings convertSettings)
        {
            if (familySymbol == null)
            {
                return(null);
            }

            TagType result = convertSettings?.GetObject <TagType>(familySymbol.Id);

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

            result = new TagType(familySymbol.Name);
            if (result != null)
            {
                Modify.SetValues(familySymbol, result);
                result.SetValue(ElementParameter.RevitId, Query.IntegerId(familySymbol));
                convertSettings?.Add(familySymbol.Id, result);
            }

            return(result);
        }
示例#15
0
        public static ApertureConstruction ToSAM_ApertureConstruction(this FamilySymbol familySymbol, ConvertSettings convertSettings)
        {
            if (familySymbol == null)
            {
                return(null);
            }

            ApertureConstruction result = convertSettings?.GetObject <ApertureConstruction>(familySymbol.Id);

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

            string name = familySymbol.FullName();

            ApertureType apertureType = familySymbol.ApertureType();

            List <ApertureConstruction> apertureConstructions = Analytical.ActiveSetting.Setting.GetValue <ApertureConstructionLibrary>(AnalyticalSettingParameter.DefaultApertureConstructionLibrary).GetApertureConstructions(apertureType);

            if (apertureConstructions != null)
            {
                result = apertureConstructions.Find(x => name.Equals(x.UniqueName()) || name.Equals(x.Name));
            }

            if (result == null)
            {
                result = new ApertureConstruction(name, apertureType);
            }

            result.UpdateParameterSets(familySymbol, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));

            convertSettings?.Add(familySymbol.Id, result);

            return(result);
        }
示例#16
0
        public static FilledRegionType ToSAM(this Autodesk.Revit.DB.FilledRegionType filledRegionType, ConvertSettings convertSettings)
        {
            if (filledRegionType == null)
            {
                return(null);
            }

            FilledRegionType result = convertSettings?.GetObject <FilledRegionType>(filledRegionType.Id);

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

            result = new FilledRegionType(filledRegionType.Name);

            if (result != null)
            {
                result.UpdateParameterSets(filledRegionType, ActiveSetting.Setting.GetValue <TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));
                convertSettings?.Add(filledRegionType.Id, result);
            }

            return(result);
        }
示例#17
0
        public static OpeningType ToSAM_OpeningType(this FamilySymbol familySymbol, ConvertSettings convertSettings)
        {
            if (familySymbol == null)
            {
                return(null);
            }


            OpeningType result = convertSettings?.GetObject <OpeningType>(familySymbol.Id);

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

            string name = familySymbol.Name;

            switch ((BuiltInCategory)familySymbol.Category.Id.IntegerValue)
            {
            case BuiltInCategory.OST_Windows:
            case BuiltInCategory.OST_CurtainWallPanels:
                result = new WindowType(name);
                break;

            case BuiltInCategory.OST_Doors:
                result = new DoorType(name);
                break;
            }

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

            Dictionary <ElementId, List <Shell> > materialElementIdsDictionary = Geometry.Revit.Query.MaterialElementIdsDictionary(familySymbol);

            if (materialElementIdsDictionary != null && materialElementIdsDictionary.Count != 0)
            {
                Document document = familySymbol.Document;

                Material material_Transparent  = null;
                double   volume_Transparent    = double.MinValue;
                double   thickness_Transparent = 0;

                Material material_Opaque  = null;
                double   volume_Opaque    = double.MinValue;
                double   thickness_Opaque = 0;


                foreach (KeyValuePair <ElementId, List <Shell> > keyValuePair in materialElementIdsDictionary)
                {
                    Material material = document.GetElement(keyValuePair.Key) as Material;
                    if (material == null)
                    {
                        continue;
                    }

                    double volume = keyValuePair.Value.ConvertAll(x => x.Volume()).Sum();
                    if (Core.Revit.Query.IsTransparent(material))
                    {
                        if (volume_Transparent < volume)
                        {
                            volume_Transparent    = volume;
                            material_Transparent  = material;
                            thickness_Transparent = Geometry.Spatial.Query.MinDimension(keyValuePair.Value.ConvertAll(x => x.GetBoundingBox()));
                        }
                    }
                    else
                    {
                        if (volume_Opaque < volume)
                        {
                            volume_Opaque    = volume;
                            material_Opaque  = material;
                            thickness_Opaque = Geometry.Spatial.Query.MinDimension(keyValuePair.Value.ConvertAll(x => x.GetBoundingBox()));
                        }
                    }
                }

                if (material_Transparent != null)
                {
                    List <Architectural.MaterialLayer> materialLayers = new List <Architectural.MaterialLayer>();
                    materialLayers.Add(new Architectural.MaterialLayer(material_Transparent.Name, thickness_Transparent));
                    result.PaneMaterialLayers = materialLayers;
                }

                if (material_Opaque != null)
                {
                    List <Architectural.MaterialLayer> materialLayers = new List <Architectural.MaterialLayer>();
                    materialLayers.Add(new Architectural.MaterialLayer(material_Opaque.Name, thickness_Opaque));
                    result.FrameMaterialLayers = materialLayers;
                }
            }

            result.UpdateParameterSets(familySymbol);

            convertSettings?.Add(familySymbol.Id, result);

            return(result);
        }
示例#18
0
        public static AnalyticalModel ToSAM_AnalyticalModel(this Document document, ConvertSettings convertSettings)
        {
            if (document == null)
            {
                return(null);
            }

            ProjectInfo projectInfo = document.ProjectInformation;

            AnalyticalModel result = convertSettings?.GetObject <AnalyticalModel>(projectInfo?.Id);

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

            Core.Location location = Core.Revit.Query.Location(document);
            Address       address  = null;

            if (projectInfo != null)
            {
                address = new Address(Guid.NewGuid(), projectInfo.BuildingName, projectInfo.Address, null, null, CountryCode.Undefined);
            }

            AdjacencyCluster adjacencyCluster = new AdjacencyCluster();

            EnergyAnalysisDetailModelOptions energyAnalysisDetailModelOptions = new EnergyAnalysisDetailModelOptions();

            energyAnalysisDetailModelOptions.Tier                   = EnergyAnalysisDetailModelTier.SecondLevelBoundaries;
            energyAnalysisDetailModelOptions.EnergyModelType        = EnergyModelType.SpatialElement;
            energyAnalysisDetailModelOptions.ExportMullions         = true;
            energyAnalysisDetailModelOptions.IncludeShadingSurfaces = true;
            energyAnalysisDetailModelOptions.SimplifyCurtainSystems = false;

            EnergyDataSettings energyDataSettings = EnergyDataSettings.GetFromDocument(document);

            energyDataSettings.ExportComplexity = gbXMLExportComplexity.ComplexWithMullionsAndShadingSurfaces;
            energyDataSettings.ExportDefaults   = false;
#if Revit2017 || Revit2018 || Revit2019 || Revit2020
            energyDataSettings.SliverSpaceTolerance = UnitUtils.ConvertToInternalUnits(0.005, DisplayUnitType.DUT_METERS);
#else
            energyDataSettings.SliverSpaceTolerance = UnitUtils.ConvertToInternalUnits(0.005, UnitTypeId.Meters);
#endif
            energyDataSettings.AnalysisType = AnalysisMode.BuildingElements;
            energyDataSettings.EnergyModel  = false;

            //Reseting Project Base Point
            IEnumerable <Element> elements = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_ProjectBasePoint);
            foreach (Element element in elements)
            {
                if (element.Pinned)
                {
                    element.Pinned = false;
                }

                Parameter parameter = null;

                parameter = element.get_Parameter(BuiltInParameter.BASEPOINT_EASTWEST_PARAM);
                if (parameter != null && !parameter.IsReadOnly)
                {
                    parameter.Set(0.0);
                }

                parameter = element.get_Parameter(BuiltInParameter.BASEPOINT_NORTHSOUTH_PARAM);
                if (parameter != null && !parameter.IsReadOnly)
                {
                    parameter.Set(0.0);
                }

                parameter = element.get_Parameter(BuiltInParameter.BASEPOINT_ELEVATION_PARAM);
                if (parameter != null && !parameter.IsReadOnly)
                {
                    parameter.Set(0.0);
                }

                parameter = element.get_Parameter(BuiltInParameter.BASEPOINT_ELEVATION_PARAM);
                if (parameter != null && !parameter.IsReadOnly)
                {
                    parameter.Set(0.0);
                }

                parameter = element.get_Parameter(BuiltInParameter.BASEPOINT_ANGLETON_PARAM);
                if (parameter != null && !parameter.IsReadOnly)
                {
                    parameter.Set(0.0);
                }
            }

            //AnalyticalSpaces
            EnergyAnalysisDetailModel   energyAnalysisDetailModel         = EnergyAnalysisDetailModel.Create(document, energyAnalysisDetailModelOptions);
            IList <EnergyAnalysisSpace> energyAnalysisSpaces              = energyAnalysisDetailModel.GetAnalyticalSpaces();
            Dictionary <string, Tuple <Panel, List <Space> > > dictionary = new Dictionary <string, Tuple <Panel, List <Space> > >();
            foreach (EnergyAnalysisSpace energyAnalysisSpace in energyAnalysisSpaces)
            {
                try
                {
                    if (energyAnalysisSpace.Area <= Core.Tolerance.MacroDistance)
                    {
                        continue;
                    }

                    Space space = energyAnalysisSpace.ToSAM(convertSettings);
                    if (space == null)
                    {
                        continue;
                    }

                    Shell shell = Geometry.Revit.Convert.ToSAM(energyAnalysisSpace.GetClosedShell());
                    if (shell == null)
                    {
                        continue;
                    }

                    adjacencyCluster.AddObject(space);

                    foreach (EnergyAnalysisSurface energyAnalysisSurface in energyAnalysisSpace.GetAnalyticalSurfaces())
                    {
                        Tuple <Panel, List <Space> > tuple;
                        if (!dictionary.TryGetValue(energyAnalysisSurface.SurfaceName, out tuple))
                        {
                            Panel panel = energyAnalysisSurface.ToSAM(convertSettings, shell);
                            if (panel == null)
                            {
                                continue;
                            }

                            tuple = new Tuple <Panel, List <Space> >(panel, new List <Space>());
                            dictionary[energyAnalysisSurface.SurfaceName] = tuple;
                        }

                        tuple.Item2.Add(space);
                    }
                }
                catch
                {
                }
            }

            #region Additional Checks (WIP)
            //Additional Check for wrongly recoginzed internal panels (WIP)
            List <Tuple <string, Panel, Space, Face3D> > tuples_External = new List <Tuple <string, Panel, Space, Face3D> >();
            foreach (KeyValuePair <string, Tuple <Panel, List <Space> > > keyValuePair in dictionary)
            {
                Tuple <Panel, List <Space> > tuple = keyValuePair.Value;
                if (tuple.Item1 != null && tuple.Item2 != null && tuple.Item2.Count == 1)
                {
                    Face3D face3D = tuple.Item1.GetFace3D();
                    if (face3D != null)
                    {
                        tuples_External.Add(new Tuple <string, Panel, Space, Face3D>(keyValuePair.Key, tuple.Item1, tuple.Item2[0], face3D));
                    }
                }
            }

            while (tuples_External.Count > 0)
            {
                Tuple <string, Panel, Space, Face3D> tuple = tuples_External[0];
                tuples_External.RemoveAt(0);

                Point3D point3D = tuple.Item4.InternalPoint3D();
                if (point3D == null)
                {
                    continue;
                }

                List <Tuple <string, Panel, Space, Face3D> > tuples_Overlap = tuples_External.FindAll(x => x.Item4.Inside(point3D));
                if (tuples_Overlap.Count != 1)
                {
                    continue;
                }

                tuples_Overlap.Add(tuple);

                tuples_Overlap.Sort((x, y) => y.Item4.GetArea().CompareTo(x.Item4.GetArea()));

                tuple = tuples_Overlap[0];
                Tuple <string, Panel, Space, Face3D> tuple_Overlap = tuples_Overlap[1];

                dictionary[tuple.Item1].Item2.Add(tuple_Overlap.Item3);
                dictionary[tuple_Overlap.Item1] = new Tuple <Panel, List <Space> >(Analytical.Create.Panel(dictionary[tuple_Overlap.Item1].Item1, PanelType.Shade), null);
                int index = tuples_External.IndexOf(tuple_Overlap);
                if (index != -1)
                {
                    tuples_External.RemoveAt(index);
                }
            }
            #endregion

            foreach (Tuple <Panel, List <Space> > tuple in dictionary.Values)
            {
                Panel panel = tuple.Item1;

                adjacencyCluster.AddObject(panel);
                tuple.Item2?.ForEach(x => adjacencyCluster.AddRelation(x, panel));
            }

            //AnalyticalShadingSurfaces
            IList <EnergyAnalysisSurface> analyticalShadingSurfaces = energyAnalysisDetailModel.GetAnalyticalShadingSurfaces();
            foreach (EnergyAnalysisSurface energyAnalysisSurface in analyticalShadingSurfaces)
            {
                try
                {
                    Panel panel = energyAnalysisSurface.ToSAM(convertSettings);
                    if (panel == null)
                    {
                        continue;
                    }

                    panel = Analytical.Create.Panel(panel, PanelType.Shade);

                    adjacencyCluster.AddObject(panel);
                }
                catch
                {
                }
            }

            adjacencyCluster.MapZones();

            IEnumerable <IMaterial> materials       = Analytical.Query.Materials(adjacencyCluster, Analytical.ActiveSetting.Setting.GetValue <MaterialLibrary>(AnalyticalSettingParameter.DefaultMaterialLibrary));
            MaterialLibrary         materialLibrary = Core.Create.MaterialLibrary("Default Material Library", materials);

            IEnumerable <Profile> profiles       = Analytical.Query.Profiles(adjacencyCluster, Analytical.ActiveSetting.Setting.GetValue <ProfileLibrary>(AnalyticalSettingParameter.DefaultProfileLibrary));
            ProfileLibrary        profileLibrary = new ProfileLibrary("Default Profile Library", profiles);

            result = new AnalyticalModel(document.Title, null, location, address, adjacencyCluster, materialLibrary, profileLibrary);
            result.UpdateParameterSets(document.ProjectInformation, ActiveSetting.Setting.GetValue <TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));

            convertSettings?.Add(projectInfo.Id, result);

            return(result);
        }
示例#19
0
        public static Space ToSAM(this SpatialElement spatialElement, ConvertSettings convertSettings)
        {
            if (spatialElement == null)
            {
                return(null);
            }

            Point3D point3D = null;

            Space result = convertSettings?.GetObject <Space>(spatialElement.Id);

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

            if (spatialElement.Location != null)
            {
                point3D = ((LocationPoint)spatialElement.Location).Point.ToSAM();
            }

            string name = Core.Revit.Query.Name(spatialElement);

            if (string.IsNullOrWhiteSpace(name))
            {
                name = spatialElement.Name;
            }

            result = new Space(name, point3D);
            result.UpdateParameterSets(spatialElement, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));

            result.InternalCondition = ToSAM_InternalCondition(spatialElement, convertSettings);

            ElementId elementId_Level = spatialElement.LevelId;

            if (elementId_Level != null && elementId_Level != ElementId.InvalidElementId)
            {
                Level level = spatialElement.Document?.GetElement(elementId_Level) as Level;
                if (level != null)
                {
                    result.SetValue(SpaceParameter.LevelName, level.Name);
                }
            }

            double area;

            if (!result.TryGetValue(SpaceParameter.Area, out area) || double.IsNaN(area) || area == 0)
            {
#if Revit2017 || Revit2018 || Revit2019 || Revit2020
                result.SetValue(SpaceParameter.Area, UnitUtils.ConvertFromInternalUnits(spatialElement.Area, DisplayUnitType.DUT_SQUARE_METERS));
#else
                result.SetValue(SpaceParameter.Area, UnitUtils.ConvertFromInternalUnits(spatialElement.Area, UnitTypeId.SquareMeters));
#endif
            }

            double volume;
            if (!result.TryGetValue(SpaceParameter.Volume, out volume) || double.IsNaN(volume) || volume == 0)
            {
                Parameter parameter = spatialElement.get_Parameter(BuiltInParameter.ROOM_VOLUME);
                if (parameter != null && parameter.HasValue)
                {
#if Revit2017 || Revit2018 || Revit2019 || Revit2020
                    result.SetValue(SpaceParameter.Volume, UnitUtils.ConvertFromInternalUnits(parameter.AsDouble(), DisplayUnitType.DUT_CUBIC_METERS));
#else
                    result.SetValue(SpaceParameter.Volume, UnitUtils.ConvertFromInternalUnits(parameter.AsDouble(), UnitTypeId.CubicMeters));
#endif
                }
            }

            convertSettings?.Add(spatialElement.Id, result);

            return(result);
        }
示例#20
0
        public static Tag ToSAM(this IndependentTag independentTag, ConvertSettings convertSettings)
        {
            if (independentTag == null)
            {
                return(null);
            }

            Document document = independentTag.Document;

            if (document == null)
            {
                return(null);
            }

            Tag result = convertSettings?.GetObject <Tag>(independentTag.Id);

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

            TagType tagType = ToSAM_TagType(document.GetElement(independentTag.GetTypeId()) as FamilySymbol, convertSettings);

            if (tagType == null)
            {
                return(null);
            }

            ElementId elementId = independentTag.OwnerViewId;

            if (elementId == null)
            {
                return(null);
            }

            View view = document.GetElement(elementId) as View;

            if (view == null)
            {
                return(null);
            }

            IntegerId viewId = Query.IntegerId(view);

#if Revit2017
            IntegerId referenceId = null;
#else
            IntegerId referenceId = Query.IntegerId(document.GetElement(independentTag.GetTaggedReference()));
#endif

            if (referenceId == null)
            {
                return(null);
            }

            Spatial.Point3D location = ToSAM(independentTag.TagHeadPosition);
            if (location == null)
            {
                return(null);
            }

            Planar.Point2D elbow = null;
            Planar.Point2D end   = null;
            if (independentTag.HasLeader)
            {
#if Revit2017
#else
                if (independentTag.HasElbow)
                {
                    Spatial.Point3D elbow3D = ToSAM(independentTag.LeaderElbow);
                    if (elbow3D != null)
                    {
                        elbow = new Planar.Point2D(elbow3D.X, elbow3D.Y);
                    }
                }
#endif

                if (independentTag.LeaderEndCondition == LeaderEndCondition.Free)
                {
                    Spatial.Point3D end3D = ToSAM(independentTag.LeaderEnd);
                    if (end3D != null)
                    {
                        end = new Planar.Point2D(end3D.X, end3D.Y);
                    }
                }
            }

            result = new Tag(tagType, viewId, new Planar.Point2D(location.X, location.Y), elbow, end, referenceId);
            if (result != null)
            {
                result.SetValue(ElementParameter.RevitId, Query.IntegerId(independentTag));
                result.SetValue(TagParameter.Leader, independentTag.HasLeader);
                result.SetValue(TagParameter.Orientation, independentTag.TagOrientation.ToString());

                Core.Revit.Modify.SetValues(independentTag, result);

                convertSettings?.Add(independentTag.Id, result);
            }

            return(result);
        }
示例#21
0
        public static IOpening ToSAM_Opening(this FamilyInstance familyInstance, ConvertSettings convertSettings)
        {
            if (familyInstance == null)
            {
                return(null);
            }

            IOpening result = convertSettings?.GetObject <IOpening>(familyInstance.Id);

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

            if (Core.Revit.Query.Simplified(familyInstance))
            {
                result = Core.Revit.Query.IJSAMObjects <IOpening>(familyInstance)?.FirstOrDefault();
                if (result != null)
                {
                    convertSettings?.Add(familyInstance.Id, result);
                    return(result);
                }
            }

            Point3D point3D_Location = Geometry.Revit.Query.LocationPoint3D(familyInstance);

            if (point3D_Location == null)
            {
                List <Solid> solids = Core.Revit.Query.Solids(familyInstance, new Options());
                solids?.RemoveAll(x => x.Volume == 0);
                if (solids == null || solids.Count == 0)
                {
                    return(null);
                }

                if (solids.Count > 1)
                {
                    solids.Sort((x, y) => y.Volume.CompareTo(x.Volume));
                }

                point3D_Location = solids[0].ComputeCentroid()?.ToSAM();
            }

            if (point3D_Location == null)
            {
                return(null);
            }

            OpeningType openingType = ToSAM_OpeningType(familyInstance.Symbol, convertSettings);

            if (openingType == null)
            {
                return(null);
            }

            BuiltInCategory builtInCategory_Host = BuiltInCategory.INVALID;

            HostObject hostObject = familyInstance.Host as HostObject;

            if (hostObject != null)
            {
                builtInCategory_Host = (BuiltInCategory)hostObject.Category.Id.IntegerValue;
            }

            Vector3D axisX  = null;
            Vector3D normal = null;
            Vector3D axisY  = null;

            if (builtInCategory_Host == BuiltInCategory.OST_Roofs)
            {
                axisX  = familyInstance.HandOrientation.ToSAM_Vector3D(false);
                axisY  = familyInstance.FacingOrientation.ToSAM_Vector3D(false);
                normal = Geometry.Spatial.Query.AxisY(axisY, axisX);
            }
            else
            {
                axisX  = familyInstance.HandOrientation.ToSAM_Vector3D(false);
                normal = familyInstance.FacingOrientation.ToSAM_Vector3D(false);
                axisY  = Geometry.Spatial.Query.AxisY(normal, axisX);
            }


            Geometry.Spatial.Plane plane = Geometry.Spatial.Create.Plane(point3D_Location, axisX, axisY);
            if (!plane.Normal.SameHalf(normal))
            {
                plane.FlipZ(false);
            }

            List <Face3D> face3Ds = Geometry.Revit.Convert.ToSAM_Geometries <Face3D>(familyInstance);

            if (face3Ds == null || face3Ds.Count == 0)
            {
                return(null);
            }

            List <Point2D> point2Ds = new List <Point2D>();

            foreach (Face3D face3D_Temp in face3Ds)
            {
                IClosedPlanar3D closedPlanar3D = face3D_Temp.GetExternalEdge3D();
                if (closedPlanar3D is ICurvable3D)
                {
                    List <ICurve3D> curve3Ds = ((ICurvable3D)closedPlanar3D).GetCurves();
                    foreach (ICurve3D curve3D in curve3Ds)
                    {
                        ICurve3D curve3D_Temp = plane.Project(curve3D);
                        point2Ds.Add(plane.Convert(curve3D_Temp.GetStart()));
                    }
                }
            }

            if (point2Ds == null || point2Ds.Count == 0)
            {
                return(null);
            }

            Rectangle2D rectangle2D = Geometry.Planar.Create.Rectangle2D(point2Ds);

            result = Analytical.Create.Opening(openingType, new Face3D(plane, rectangle2D));
            result.UpdateParameterSets(familyInstance);

            convertSettings?.Add(familyInstance.Id, result);

            return(result);
        }
示例#22
0
        public static Autodesk.Revit.DB.Mechanical.Space ToRevit(this Space space, Document document, ConvertSettings convertSettings)
        {
            if (space == null)
            {
                return(null);
            }

            Autodesk.Revit.DB.Mechanical.Space result = convertSettings?.GetObject <Autodesk.Revit.DB.Mechanical.Space>(space.Guid);
            if (result != null)
            {
                return(result);
            }

            if (!convertSettings.RemoveExisting)
            {
                result = Core.Revit.Query.Element <Autodesk.Revit.DB.Mechanical.Space>(document, space);
            }

            if (result == null)
            {
                double lowElevation = Query.LowElevation(space);
                if (double.IsNaN(lowElevation))
                {
                    return(null);
                }

                Level level = Geometry.Revit.Query.LowLevel(document, lowElevation);
                if (level == null)
                {
                    return(null);
                }

#if Revit2017 || Revit2018 || Revit2019 || Revit2020
                result = document.Create.NewSpace(level, new UV(UnitUtils.ConvertToInternalUnits(space.Location.X, DisplayUnitType.DUT_METERS), UnitUtils.ConvertToInternalUnits(space.Location.Y, DisplayUnitType.DUT_METERS)));
#else
                result = document.Create.NewSpace(level, new UV(UnitUtils.ConvertToInternalUnits(space.Location.X, UnitTypeId.Meters), UnitUtils.ConvertToInternalUnits(space.Location.Y, UnitTypeId.Meters)));
#endif
            }

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

            //result.get_Parameter(BuiltInParameter.ROOM_NAME).Set(string.Empty);
            //result.get_Parameter(BuiltInParameter.ROOM_NUMBER).Set(space.Name);

            result.get_Parameter(BuiltInParameter.ROOM_NAME).Set(space.Name);

            if (convertSettings.ConvertParameters)
            {
                Dictionary <string, object> parameters = convertSettings.GetParameters();

                InternalCondition internalCondition = space.InternalCondition;
                if (internalCondition != null)
                {
                    Core.Revit.Modify.SetValues(result, internalCondition);
                    Core.Revit.Modify.SetValues(result, internalCondition, ActiveSetting.Setting, parameters);
                }

                Core.Revit.Modify.SetValues(result, space);
                Core.Revit.Modify.SetValues(result, space, ActiveSetting.Setting, parameters);

                Core.Revit.Modify.SetJson(result, space.ToJObject()?.ToString());
            }

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

            return(result);
        }
示例#23
0
        public static FilledRegion ToSAM(this Autodesk.Revit.DB.FilledRegion filledRegion, ConvertSettings convertSettings)
        {
            if (filledRegion == null || !filledRegion.IsValidObject)
            {
                return(null);
            }

            FilledRegion result = convertSettings?.GetObject <FilledRegion>(filledRegion.Id);

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

            Document document = filledRegion.Document;

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

            Autodesk.Revit.DB.FilledRegionType filledRegionType_Revit = document.GetElement(filledRegion.GetTypeId()) as Autodesk.Revit.DB.FilledRegionType;
            if (filledRegionType_Revit == null)
            {
                return(null);
            }

            View view = filledRegion.Document.GetElement(filledRegion.OwnerViewId) as View;

            if (view == null)
            {
                return(null);
            }

            Spatial.Plane plane = view.Plane();
            if (plane == null)
            {
                return(null);
            }

            List <Face3D> face3Ds = filledRegion.Face3Ds();

            if (face3Ds == null)
            {
                return(null);
            }

            FilledRegionType     filledRegionType = filledRegionType_Revit.ToSAM(convertSettings);
            List <Planar.Face2D> face2Ds          = face3Ds.ConvertAll(x => Spatial.Query.Convert(plane, x));
            IntegerId            integerId        = Query.IntegerId(view);

            result = new FilledRegion(filledRegionType, integerId, face2Ds);

            if (result != null)
            {
                result.UpdateParameterSets(filledRegion, ActiveSetting.Setting.GetValue <TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));
                convertSettings?.Add(filledRegion.Id, result);
            }

            return(result);
        }
示例#24
0
        public static Panel ToSAM(this EnergyAnalysisSurface energyAnalysisSurface, ConvertSettings convertSettings, Shell shell = null, double silverSpacing = Core.Tolerance.MacroDistance, double tolerance = Core.Tolerance.Distance)
        {
            if (energyAnalysisSurface == null)
            {
                return(null);
            }

            Panel result = convertSettings?.GetObject <Panel>(energyAnalysisSurface.Id);

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

            Document document = energyAnalysisSurface.Document;

            Polygon3D polygon3D = energyAnalysisSurface.GetPolyloop().ToSAM();

            if (polygon3D == null)
            {
                return(null);
            }

            if (shell != null)
            {
                Geometry.Spatial.Plane plane = polygon3D.GetPlane();

                if (plane != null)
                {
                    Point3D point3D = polygon3D.InternalPoint3D();
                    if (point3D != null)
                    {
                        Vector3D normal = shell.Normal(polygon3D.InternalPoint3D(), true, silverSpacing, tolerance);
                        if (!normal.SameHalf(plane.AxisZ))
                        {
                            plane.FlipZ();
                            polygon3D = new Polygon3D(plane, polygon3D.GetPoints().ConvertAll(x => plane.Convert(x)));
                        }
                    }
                }
            }

            HostObject hostObject = Core.Revit.Query.Element(document, energyAnalysisSurface.CADObjectUniqueId, energyAnalysisSurface.CADLinkUniqueId) as HostObject;

            if (hostObject == null)
            {
                return(Analytical.Create.Panel(null, PanelType.Air, new Face3D(polygon3D)));
            }

            ElementId elementId_Type = hostObject.GetTypeId();

            if (elementId_Type == null || elementId_Type == ElementId.InvalidElementId)
            {
                return(null);
            }

            PanelType    panelType    = Query.PanelType(hostObject);
            Construction construction = ((HostObjAttributes)hostObject.Document.GetElement(elementId_Type)).ToSAM(convertSettings);

            if (construction == null)
            {
                construction = Analytical.Query.DefaultConstruction(panelType); //Default Construction
            }
            PanelType panelType_Temp = Query.PanelType(construction);

            if (panelType_Temp != PanelType.Undefined)
            {
                panelType = panelType_Temp;
            }

            Face3D face3D = new Face3D(polygon3D);

            result = Analytical.Create.Panel(construction, panelType, face3D);

            IEnumerable <EnergyAnalysisOpening> energyAnalysisOpenings = energyAnalysisSurface.GetAnalyticalOpenings();

            if (energyAnalysisOpenings != null && energyAnalysisOpenings.Count() != 0)
            {
                foreach (EnergyAnalysisOpening energyAnalysisOpening in energyAnalysisOpenings)
                {
                    Aperture aperture = energyAnalysisOpening.ToSAM(convertSettings);
                    if (aperture != null)
                    {
                        result.AddAperture(aperture);
                    }
                }
            }

            result.UpdateParameterSets(energyAnalysisSurface, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));

            convertSettings?.Add(energyAnalysisSurface.Id, result);

            return(result);
        }
示例#25
0
        public static Construction ToSAM(this HostObjAttributes hostObjAttributes, ConvertSettings convertSettings)
        {
            if (hostObjAttributes == null)
            {
                return(null);
            }

            Construction result = convertSettings?.GetObject <Construction>(hostObjAttributes.Id);

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

            string    name      = hostObjAttributes.Name;
            PanelType panelType = hostObjAttributes.PanelType();

            if (panelType == PanelType.Undefined)
            {
                panelType = Query.PanelType((BuiltInCategory)hostObjAttributes.Category.Id.IntegerValue);
            }

            Construction construction = Analytical.Query.DefaultConstruction(panelType);

            if (construction != null && (name.Equals(construction.Name) || name.Equals(construction.UniqueName())))
            {
                result = new Construction(construction);
            }
            else
            {
                result = new Construction(hostObjAttributes.Name);
            }


            result.UpdateParameterSets(hostObjAttributes, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));

            //result.Add(Core.Revit.Query.ParameterSet(hostObjAttributes));

            convertSettings?.Add(hostObjAttributes.Id, result);

            if (panelType != PanelType.Undefined)
            {
                result.SetValue(ConstructionParameter.DefaultPanelType, panelType.Text());
            }
            else
            {
                result.SetValue(ConstructionParameter.DefaultPanelType, null);
            }

            List <ConstructionLayer> constructionLayers = result.ConstructionLayers;

            if (constructionLayers != null && constructionLayers.Count != 0)
            {
                result.SetValue(ConstructionParameter.DefaultThickness, constructionLayers.ConvertAll(x => x.Thickness).Sum());
            }
            else
            {
                CompoundStructure compoundStructure = hostObjAttributes.GetCompoundStructure();
                if (compoundStructure != null)
                {
#if Revit2017 || Revit2018 || Revit2019 || Revit2020
                    double thickness = UnitUtils.ConvertFromInternalUnits(compoundStructure.GetWidth(), DisplayUnitType.DUT_METERS);
#else
                    double thickness = UnitUtils.ConvertFromInternalUnits(compoundStructure.GetWidth(), UnitTypeId.Meters);
#endif
                    result.SetValue(ConstructionParameter.DefaultThickness, thickness);
                }
            }


            return(result);
        }
示例#26
0
        public static Autodesk.Revit.DB.Level ToRevit(this Level level, Document document, ConvertSettings convertSettings)
        {
            if (level == null || document == null)
            {
                return(null);
            }

            Autodesk.Revit.DB.Level result = convertSettings?.GetObject <Autodesk.Revit.DB.Level>(level.Guid);
            if (result != null)
            {
                return(result);
            }

            if (!convertSettings.RemoveExisting)
            {
                result = Core.Revit.Query.Element <Autodesk.Revit.DB.Level>(document, level);
            }

            double elevation = level.Elevation;

            if (double.IsNaN(elevation))
            {
                return(null);
            }

#if Revit2017 || Revit2018 || Revit2019 || Revit2020
            elevation = UnitUtils.ConvertToInternalUnits(elevation, DisplayUnitType.DUT_METERS);
#else
            elevation = UnitUtils.ConvertToInternalUnits(elevation, UnitTypeId.Meters);
#endif


            if (result == null)
            {
                List <Autodesk.Revit.DB.Level> levels = new FilteredElementCollector(document).OfClass(typeof(Autodesk.Revit.DB.Level)).Cast <Autodesk.Revit.DB.Level>().ToList();
                if (levels != null && levels.Count != 0)
                {
                    result = levels.Find(x => x.Elevation.Equals(elevation));
                }
            }

            if (convertSettings.RemoveExisting)
            {
                ElementId elementId = level.ElementId();
                if (elementId != null && elementId != ElementId.InvalidElementId)
                {
                    Element element = document.GetElement(elementId) as Autodesk.Revit.DB.Level;
                    if (element != null)
                    {
                        document.Delete(elementId);
                    }
                }
            }

            if (result == null)
            {
                result = Autodesk.Revit.DB.Level.Create(document, elevation);
            }

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

            //TODO: Implement method to properly rename element
            try
            {
                result.Name = level.Name;
            }
            catch (Exception exception)
            {
            }


            if (convertSettings.ConvertParameters)
            {
                Core.Revit.Modify.SetValues(result, level);
                Core.Revit.Modify.SetValues(result, level, ActiveSetting.Setting);

                Core.Revit.Modify.SetJson(result, level.ToJObject()?.ToString());
            }

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

            return(result);
        }