/***************************************************/ /**** Public methods - Materials ****/ /***************************************************/ public static void CopyCharacteristics(this SolidMaterial toMaterial, Material fromMaterial) { if (fromMaterial == null) { toMaterial.NullRevitElementWarning(); return; } ElementId elementID = fromMaterial.ThermalAssetId; if (elementID == null || elementID == ElementId.InvalidElementId) { toMaterial.NullThermalAssetWarning(); return; } PropertySetElement propertySetElement = fromMaterial.Document.GetElement(elementID) as PropertySetElement; ThermalAsset thermalAsset = propertySetElement?.GetThermalAsset(); if (thermalAsset == null) { Compute.NullThermalAssetWarning(toMaterial); return; } toMaterial.CopyCharacteristics(thermalAsset); }
void GetElementMaterialInfo(Document doc) { FilteredElementCollector collector = new FilteredElementCollector(doc) .WhereElementIsNotElementType() .OfClass(typeof(Material)); try { foreach (Material material in collector) { if (material.Name.Equals("Air")) { AppearanceAssetElement appearanceElement = doc.GetElement(material.AppearanceAssetId) as AppearanceAssetElement; Asset appearanceAsset = appearanceElement .GetRenderingAsset(); List <AssetProperty> assetProperties = new List <AssetProperty>(); PropertySetElement physicalPropSet = doc.GetElement(material.StructuralAssetId) as PropertySetElement; PropertySetElement thermalPropSet = doc.GetElement(material.ThermalAssetId) as PropertySetElement; ThermalAsset thermalAsset = thermalPropSet .GetThermalAsset(); StructuralAsset physicalAsset = physicalPropSet .GetStructuralAsset(); ICollection <Parameter> physicalParameters = physicalPropSet.GetOrderedParameters(); ICollection <Parameter> thermalParameters = thermalPropSet.GetOrderedParameters(); // Appearance Asset for (int i = 0; i < appearanceAsset.Size; i++) { AssetProperty property = appearanceAsset[i]; assetProperties.Add(property); } foreach (AssetProperty assetProp in assetProperties) { Type type = assetProp.GetType(); object assetPropValue = null; var prop = type.GetProperty("Value"); if (prop != null && prop.GetIndexParameters().Length == 0) { assetPropValue = prop.GetValue(assetProp); } } // Physical (Structural) Asset foreach (Parameter p in physicalParameters) { // Work with parameters here // The only parameter not in the orderedParameters // that is needed is the Asset name, which you // can get by 'physicalAsset.Name'. } // Thermal Asset foreach (Parameter p in thermalParameters) { //Work with parameters here //The only parameter not in the orderedParameters // that is needed is the Asset name, shich you // can get by 'thermalAsset.Name'. } } } } catch (Exception e) { Console.WriteLine(e.ToString()); } }
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); }
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); }