Esempio n. 1
0
        public static IRevitInstance ToSAM(this FamilyInstance familyInstance, ConvertSettings convertSettings)
        {
            if (familyInstance == null)
            {
                return(null);
            }

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

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



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

            return(result);
        }
Esempio n. 2
0
        public static Material ToSAM(this Autodesk.Revit.DB.Material material, ConvertSettings convertSettings)
        {
            if (material == null)
            {
                return(null);
            }

            Material result = convertSettings?.GetObject <Material>(material.Id);

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

            Document document = material.Document;

            double density             = double.NaN;
            double thermalConductivity = double.NaN;
            ThermalMaterialType thermalMaterialType = ThermalMaterialType.Undefined;
            bool transmitsLight = false;

            ElementId elementId = material.ThermalAssetId;

            if (elementId != null && elementId != ElementId.InvalidElementId)
            {
                PropertySetElement propertySetElement = document.GetElement(elementId) as PropertySetElement;
                if (propertySetElement != null)
                {
                    ThermalAsset thermalAsset = propertySetElement.GetThermalAsset();
                    if (thermalAsset != null)
                    {
                        density             = thermalAsset.Density;
                        thermalConductivity = thermalAsset.ThermalConductivity;
                        thermalMaterialType = thermalAsset.ThermalMaterialType;
                        transmitsLight      = thermalAsset.TransmitsLight;
                    }
                }
            }

            string description = material.get_Parameter(BuiltInParameter.ALL_MODEL_DESCRIPTION)?.AsString();

            if (thermalMaterialType != ThermalMaterialType.Undefined)
            {
                switch (thermalMaterialType)
                {
                case ThermalMaterialType.Gas:
                    result = new GasMaterial(System.Guid.NewGuid(), material.Name, material.Name, description, thermalConductivity, density, double.NaN, double.NaN);
                    break;

                case ThermalMaterialType.Liquid:
                    result = new LiquidMaterial(System.Guid.NewGuid(), material.Name, material.Name, description, thermalConductivity, density, double.NaN, double.NaN);
                    break;

                case ThermalMaterialType.Solid:
                    if (transmitsLight)
                    {
                        result = new TransparentMaterial(material.Name, null, material.Name, description, thermalConductivity, double.NaN, density);
                    }
                    else
                    {
                        result = new OpaqueMaterial(material.Name, null, material.Name, description, thermalConductivity, double.NaN, density);
                    }
                    break;
                }
            }

            if (result == null)
            {
                string materialClass = material.MaterialClass?.Trim();
                if (string.IsNullOrWhiteSpace(materialClass))
                {
                    switch (materialClass.ToLower())
                    {
                    case "glass":
                        result = new TransparentMaterial(material.Name, materialClass, material.Name, description, thermalConductivity, double.NaN, density);
                        break;

                    case "gas":
                        result = new GasMaterial(System.Guid.NewGuid(), material.Name, material.Name, description, thermalConductivity, density, double.NaN, double.NaN);
                        break;

                    case "ceramic":
                    case "earth":
                    case "brass":
                    case "metal":
                    case "wood":
                    case "concrete":
                    case "masonry":
                    case "paint":
                    case "paint/coating":
                    case "plastic":
                    case "stone":
                    case "textile":
                        result = new OpaqueMaterial(material.Name, materialClass, material.Name, description, thermalConductivity, double.NaN, density);
                        break;

                    case "liquid":
                        result = new LiquidMaterial(System.Guid.NewGuid(), material.Name, material.Name, description, thermalConductivity, density, double.NaN, double.NaN);
                        break;
                    }
                }
            }

            if (result == null)
            {
                int transparency = material.Transparency;
                if (transparency < 10)
                {
                    result = new OpaqueMaterial(material.Name, null, material.Name, description, thermalConductivity, double.NaN, density);
                }
                else if (transparency < 100)
                {
                    result = new TransparentMaterial(material.Name, null, material.Name, description, thermalConductivity, double.NaN, density);
                }
                else
                {
                    result = new GasMaterial(System.Guid.NewGuid(), material.Name, material.Name, description, thermalConductivity, double.NaN, density, double.NaN);
                }
            }

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


            return(result);
        }
Esempio n. 3
0
        public static Autodesk.Revit.DB.Material ToRevit(this Material material, Document document, ConvertSettings convertSettings)
        {
            if (material == null || document == null)
            {
                return(null);
            }

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

            List <Autodesk.Revit.DB.Material> materials = new FilteredElementCollector(document).OfClass(typeof(Autodesk.Revit.DB.Material)).Cast <Autodesk.Revit.DB.Material>().ToList();

            if (materials != null)
            {
                result = materials.Find(x => x.Name == material.Name);
            }

            if (result == null)
            {
                ElementId elementId = Autodesk.Revit.DB.Material.Create(document, material.Name);
                if (elementId == null || elementId == ElementId.InvalidElementId)
                {
                    return(result);
                }

                result = document.GetElement(elementId) as Autodesk.Revit.DB.Material;
                if (result == null)
                {
                    return(result);
                }
            }

            if (material is GasMaterial)
            {
                result.MaterialClass = "Gas";
            }
            else if (material is SolidMaterial)
            {
            }
            else if (material is LiquidMaterial)
            {
                result.MaterialClass = "Liquid";
            }

            Parameter parameter = result.get_Parameter(BuiltInParameter.ALL_MODEL_DESCRIPTION);

            parameter.Set(material.Description);

            ElementId elementId_ThermalAsset = result.ThermalAssetId;

            if (elementId_ThermalAsset != null && elementId_ThermalAsset != ElementId.InvalidElementId)
            {
                PropertySetElement propertySetElement = document.GetElement(elementId_ThermalAsset) as PropertySetElement;
                if (propertySetElement != null)
                {
                    ThermalAsset thermalAsset = propertySetElement.GetThermalAsset();
                    if (thermalAsset != null)
                    {
                        thermalAsset.Density             = material.Density;
                        thermalAsset.ThermalConductivity = material.ThermalConductivity;
                    }
                }
            }


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

                Modify.SetValues(result, material);
                Modify.SetValues(result, material, ActiveSetting.Setting, parameters);
            }

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

            return(result);
        }