public static string UniqueName(this HostPartitionType hostPartitionType, bool reverse = true)
        {
            if (hostPartitionType == null)
            {
                return(null);
            }

            return(UniqueName((Core.SAMType)hostPartitionType, reverse));
        }
Exemple #2
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);
        }
        public static OpaqueConstructionAbridged ToLadybugTools(this HostPartitionType hostPartitionType, bool reverse = true)
        {
            if (hostPartitionType == null)
            {
                return(null);
            }

            List <Architectural.MaterialLayer> materialLayers = hostPartitionType.MaterialLayers;

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

            if (reverse)
            {
                materialLayers.Reverse();
            }


            OpaqueConstructionAbridged result = new OpaqueConstructionAbridged(Query.UniqueName(hostPartitionType, reverse), materialLayers.ConvertAll(x => x.Name), hostPartitionType.Name);

            return(result);
        }
Exemple #4
0
        public static List <IPartition> ToSAM_Partitions(this HostObject hostObject, ConvertSettings convertSettings)
        {
            if (hostObject == null)
            {
                return(null);
            }

            List <IPartition> result = convertSettings?.GetObjects <IPartition>(hostObject.Id);

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

            ElementId elementId_Type = hostObject.GetTypeId();

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

            HostPartitionType hostPartitionType = ((HostObjAttributes)hostObject.Document.GetElement(elementId_Type)).ToSAM_HostPartitionType(convertSettings);

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

            List <Face3D> face3Ds = hostObject.Profiles();

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

            LogicalOrFilter logicalOrFilter = new LogicalOrFilter(new List <ElementFilter>()
            {
                new ElementCategoryFilter(BuiltInCategory.OST_Windows), new ElementCategoryFilter(BuiltInCategory.OST_Doors)
            });

#if Revit2017
            IEnumerable <ElementId> elementIds = null;
#else
            IEnumerable <ElementId> elementIds = hostObject.GetDependentElements(logicalOrFilter);
#endif

            if (hostObject is Autodesk.Revit.DB.Wall || hostObject is CurtainSystem)
            {
                List <Autodesk.Revit.DB.Panel> panels = Core.Revit.Query.Panels(hostObject as dynamic);
                if (panels != null && panels.Count > 0)
                {
                    List <ElementId> elementIds_Temp = panels.ConvertAll(x => x.Id);
                    if (elementIds != null && elementIds.Count() > 0)
                    {
                        elementIds_Temp.AddRange(elementIds);
                    }

                    elementIds = elementIds_Temp;
                }
            }

            result = new List <IPartition>();

            foreach (Face3D face3D in face3Ds)
            {
                if (face3D == null)
                {
                    continue;
                }

                IHostPartition hostPartition = Analytical.Create.HostPartition(face3D, hostPartitionType);
                hostPartition.UpdateParameterSets(hostObject);

                if (elementIds != null && elementIds.Count() > 0)
                {
                    foreach (ElementId elementId in elementIds)
                    {
                        Element element = hostObject.Document.GetElement(elementId);
                        if (element == null)
                        {
                            continue;
                        }

                        if (!(element is FamilyInstance))
                        {
                            continue;
                        }

                        IOpening opening = ToSAM_Opening((FamilyInstance)element, convertSettings);
                        if (opening != null)
                        {
                            opening = Analytical.Query.Project(hostPartition, opening);
                            hostPartition.AddOpening(opening);
                        }
                    }
                }

                result.Add(hostPartition);
            }

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

            return(result);
        }
        public static HostObjAttributes ToRevit(this HostPartitionType hostPartitionType, Document document, Core.Revit.ConvertSettings convertSettings)
        {
            if (hostPartitionType == null)
            {
                return(null);
            }

            HostObjAttributes result = null;

            List <HostObjAttributes> hostObjAttributesList = convertSettings?.GetObjects <HostObjAttributes>(hostPartitionType.Guid);

            if (hostObjAttributesList != null)
            {
                if (hostPartitionType is WallType)
                {
                    result = hostObjAttributesList.Find(x => x is Autodesk.Revit.DB.WallType);
                }
                else if (hostPartitionType is FloorType)
                {
                    result = hostObjAttributesList.Find(x => x is Autodesk.Revit.DB.FloorType);
                }
                else if (hostPartitionType is RoofType)
                {
                    result = hostObjAttributesList.Find(x => x is Autodesk.Revit.DB.RoofType);
                }
            }

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

            FilteredElementCollector filteredElementCollector = Query.FilteredElementCollector_New(document, hostPartitionType.GetType())?.OfClass(typeof(HostObjAttributes));

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

            string familyName_Source = null;
            string typeName_Source   = null;

            if (!Core.Revit.Query.TryGetFamilyNameAndTypeName(hostPartitionType.Name, out familyName_Source, out typeName_Source))
            {
                return(null);
            }

            foreach (HostObjAttributes hostObjAttributes in filteredElementCollector)
            {
                string fullName = Core.Revit.Query.FullName(hostObjAttributes);

                string familyName = null;
                string typeName   = null;
                if (!Core.Revit.Query.TryGetFamilyNameAndTypeName(fullName, out familyName, out typeName))
                {
                    continue;
                }

                if (fullName != null && fullName.Equals(hostPartitionType.Name))
                {
                    result = hostObjAttributes;
                    break;
                }

                if (!string.IsNullOrWhiteSpace(familyName) && !string.IsNullOrWhiteSpace(familyName_Source))
                {
                    continue;
                }


                if (typeName.Equals(typeName_Source))
                {
                    result = hostObjAttributes;
                }
            }

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

            List <Architectural.MaterialLayer> materialLayers = hostPartitionType.MaterialLayers;

            if (materialLayers != null && materialLayers.Count != 0)
            {
                CompoundStructure compoundStructure = result.GetCompoundStructure();
                if (compoundStructure != null)
                {
                    List <Material> materials = new FilteredElementCollector(document).OfClass(typeof(Material)).Cast <Material>().ToList();

                    List <CompoundStructureLayer> compoundStructureLayers = new List <CompoundStructureLayer>();
                    foreach (Architectural.MaterialLayer materialLayer in materialLayers)
                    {
                        Material material = materials.Find(x => x.Name == materialLayer.Name);
                        if (material == null)
                        {
                            continue;
                        }

                        double width = double.NaN;

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



                        CompoundStructureLayer compoundStructureLayer = new CompoundStructureLayer(width, MaterialFunctionAssignment.Structure, material.Id);
                        if (compoundStructureLayer == null)
                        {
                            continue;
                        }

                        compoundStructureLayers.Add(compoundStructureLayer);
                    }

                    if (compoundStructureLayers != null && compoundStructureLayers.Count != 0)
                    {
                        compoundStructure.SetLayers(compoundStructureLayers);
                        result.SetCompoundStructure(compoundStructure);
                    }
                }
            }

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

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

            return(result);
        }
Exemple #6
0
        public static List <IAnalyticalObject> ToSAM_AnalyticalObject(this Element element, ConvertSettings convertSettings)
        {
            List <IAnalyticalObject> result = null;

            if (element is WallSweep)
            {
                List <IPartition> partitions = ToSAM_Partitions((WallSweep)element, convertSettings);
                if (partitions != null)
                {
                    result = partitions.ConvertAll(x => x as IAnalyticalObject);
                }
            }
            else if (element is HostObject)
            {
                List <IPartition> partitions = ToSAM_Partitions((HostObject)element, convertSettings);
                if (partitions != null)
                {
                    result = partitions.ConvertAll(x => x as IAnalyticalObject);
                }
            }
            else if (element is HostObjAttributes)
            {
                HostPartitionType hostPartitionType = ToSAM_HostPartitionType((HostObjAttributes)element, convertSettings);
                if (hostPartitionType != null)
                {
                    result = new List <IAnalyticalObject>()
                    {
                        hostPartitionType
                    }
                }
                ;
            }
            else if (element is SpatialElement)
            {
                Space space = ToSAM((SpatialElement)element, convertSettings);
                if (space != null)
                {
                    result = new List <IAnalyticalObject>()
                    {
                        space
                    }
                }
                ;
            }
            else if (element is FamilyInstance)
            {
                FamilyInstance familyInstance = (FamilyInstance)element;

                if (element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Windows || element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Doors)
                {
                    IOpening opening = ToSAM_Opening(familyInstance, convertSettings);
                    if (opening != null)
                    {
                        result = new List <IAnalyticalObject>()
                        {
                            opening
                        }
                    }
                    ;
                }
                else
                {
                    //result = familyInstance.ToSAM_Panels(convertSettings);
                }
            }
            else if (element is FamilySymbol)
            {
                if (element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Windows || element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Doors)
                {
                    OpeningType openingType = ToSAM_OpeningType((FamilySymbol)element, convertSettings);
                    if (openingType != null)
                    {
                        result = new List <IAnalyticalObject>()
                        {
                            openingType
                        }
                    }
                    ;
                }
            }
            else if (element is ModelCurve)
            {
                //if (element.Category != null && (element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_MEPSpaceSeparationLines || element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_RoomSeparationLines))
                //{
                //    List<Panel> panels = ToSAM_Panels((ModelCurve)element, convertSettings);
                //    if (panels != null)
                //        result = panels.ConvertAll(x => x as Core.SAMObject);
                //}
            }
            return(result);
        }