/// <summary> /// Create a new brick material /// </summary> /// <returns>The specific material</returns> private Material CreateSampleBrickMaterial() { SubTransaction createMaterial = new SubTransaction(this.m_document.Document); createMaterial.Start(); Material materialNew = null; //Try to copy an existing material. If it is not available, create a new one. Material masonry_Brick = GetMaterial("Brick, Common"); if (masonry_Brick != null) { materialNew = masonry_Brick.Duplicate(masonry_Brick.Name + "_new"); System.Diagnostics.Debug.WriteLine(masonry_Brick.MaterialClass); materialNew.MaterialClass = "Brick"; } else { ElementId idNew = Material.Create(m_document.Document, "New Brick Sample"); materialNew = m_document.Document.GetElement(idNew) as Material; materialNew.Color = new Autodesk.Revit.DB.Color(255, 0, 0); } createMaterial.Commit(); SubTransaction createPropertySets = new SubTransaction(this.m_document.Document); createPropertySets.Start(); //Create a new structural asset and set properties on it. StructuralAsset structuralAsssetBrick = new StructuralAsset("BrickStructuralAsset", Autodesk.Revit.DB.StructuralAssetClass.Generic); structuralAsssetBrick.DampingRatio = .5; PropertySetElement pseStructural = PropertySetElement.Create(m_document.Document, structuralAsssetBrick); //Create a new thermal asset and set properties on it. ThermalAsset thermalAssetBrick = new ThermalAsset("BrickThermalAsset", Autodesk.Revit.DB.ThermalMaterialType.Solid); thermalAssetBrick.Porosity = 0.1; thermalAssetBrick.Permeability = 0.2; thermalAssetBrick.Compressibility = .5; thermalAssetBrick.ThermalConductivity = .5; //Create PropertySets from assets and assign them to the material. PropertySetElement pseThermal = PropertySetElement.Create(m_document.Document, thermalAssetBrick); createPropertySets.Commit(); SubTransaction setPropertySets = new SubTransaction(this.m_document.Document); setPropertySets.Start(); materialNew.SetMaterialAspectByPropertySet(MaterialAspect.Structural, pseStructural.Id); materialNew.SetMaterialAspectByPropertySet(MaterialAspect.Thermal, pseThermal.Id); //also try //materialNew.ThermalAssetId = pseThermal.Id; setPropertySets.Commit(); return(materialNew); }
/***************************************************/ /**** 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); }
/// <summary> /// Getting the specific material by name. /// </summary> /// <param name="name">The name of specific material.</param> /// <returns>The specific material</returns> /* public static Material GetMaterialfromlibray(string name, Autodesk.Revit.ApplicationServices.Application revitApp) * { * FilteredElementCollector collector = new FilteredElementCollector(revitApp.Documents.); * collector.WherePasses(new ElementCategoryFilter(BuiltInCategory.OST_Materials)); * var MaterialElement = from element in collector * where element.Name == name * select element; * * if (MaterialElement.Count() == 0) * return null; * return MaterialElement.First<Element>() as Material; * }*/ /// <summary> /// Create a new brick material /// </summary> /// <returns>The specific material</returns> public static Material CreateSampleConcreteMaterial(UIDocument m_document) { Material materialNew = null; //Try to copy an existing material. If it is not available, create a new one. Material masonry_Concrete = GetMaterial("Concrete, Lightweight", m_document); if (masonry_Concrete != null) { TaskDialog.Show("Tip", "找到这种材料了!"); materialNew = masonry_Concrete.Duplicate(masonry_Concrete.Name + "_new"); materialNew.MaterialClass = "Concrete"; } else { ElementId idNew = Material.Create(m_document.Document, "New Concrete Sample"); materialNew = m_document.Document.GetElement(idNew) as Material; materialNew.Color = new Autodesk.Revit.DB.Color(130, 150, 120); } //创建外观属性 //Create a new structural asset and set properties on it. StructuralAsset structuralAsssetConcrete = new StructuralAsset("ConcreteStructuralAsset", Autodesk.Revit.DB.StructuralAssetClass.Concrete); structuralAsssetConcrete.ConcreteBendingReinforcement = .5; structuralAsssetConcrete.DampingRatio = .5; //Create a new thermal asset and set properties on it. ThermalAsset thermalAssetConcrete = new ThermalAsset("ConcreteThermalAsset", Autodesk.Revit.DB.ThermalMaterialType.Solid); thermalAssetConcrete.Porosity = 0.2; thermalAssetConcrete.Permeability = 0.3; thermalAssetConcrete.Compressibility = .5; thermalAssetConcrete.ThermalConductivity = .5; //Create PropertySets from assets and assign them to the material. PropertySetElement pseThermal = PropertySetElement.Create(m_document.Document, thermalAssetConcrete); PropertySetElement pseStructural = PropertySetElement.Create(m_document.Document, structuralAsssetConcrete); materialNew.SetMaterialAspectByPropertySet(MaterialAspect.Structural, pseStructural.Id); materialNew.SetMaterialAspectByPropertySet(MaterialAspect.Thermal, pseThermal.Id); return(materialNew); }
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 methods - Assets ****/ /***************************************************/ public static void CopyCharacteristics(this SolidMaterial toMaterial, ThermalAsset fromAsset) { toMaterial.Conductivity = fromAsset.ThermalConductivity.ToSI(UnitType.UT_HVAC_ThermalConductivity); toMaterial.SpecificHeat = fromAsset.SpecificHeat.ToSI(UnitType.UT_HVAC_SpecificHeat); toMaterial.Density = fromAsset.Density.ToSI(UnitType.UT_MassDensity); }
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); }