前言
自己研究了一圈材质之后,在官方文档里面翻了一下,发现也有一些介绍,整理一下。
我研究的参考:Revit API: Material 材质
内容
下面按照官方的文档做个整理。
材质基本信息
链接:General Material Information
材质的属性:一个材质包含一个或多个和渲染相关的内容,比如外观、结构等。每一个部分都会有一系列的属性来描述,这些属性被称为资源 assets
。StructuralAsset
表示该材质和结构相关的属性。ThermalAsset
表示材质和能量分析相关的内容。AppearanceAssetId
表示该材质和外观相关的属性。
// The ElementId of the AppearanceAssetElement.
public ElementId AppearanceAssetId {
get; set; }
// The ElementId of the structural PropertySetElement.
public ElementId StructuralAssetId {
get; set; }
// The ElementId of the thermal PropertySetElement.
public ElementId ThermalAssetId {
get; set; }
AppearanceAssetId 参考 Revit API: Material 材质
下面讲讲 StructuralAssetId
和 ThermalAssetId
,主要的属性是在类 Autodesk.Revit.DB.StructuralAsset
和 Autodesk.Revit.DB.ThermalAsset
里面。
获取材质的结构属性:
private void ReadMaterialProps(Document document, Material material)
{
ElementId strucAssetId = material.StructuralAssetId;
if (strucAssetId != ElementId.InvalidElementId)
{
PropertySetElement pse = document.GetElement(strucAssetId) as PropertySetElement;
if (pse != null)
{
StructuralAsset asset = pse.GetStructuralAsset();
// Check the material behavior and only read if Isotropic
if (asset.Behavior == StructuralBehavior.Isotropic)
{
// Get the class of material
StructuralAssetClass assetClass = asset.StructuralAssetClass; // Get other material properties
// Get other material properties
double poisson = asset.PoissonRatio.X;
double youngMod = asset.YoungModulus.X;
double thermCoeff = asset.ThermalExpansionCoefficient.X;
double unitweight = asset.Density;
double shearMod = asset.ShearModulus.X;
double dampingRatio = asset.DampingRatio;
if (assetClass == StructuralAssetClass.Metal)
{
double dMinStress = asset.MinimumYieldStress;
}
elseif (assetClass == StructuralAssetClass.Concrete)
{
double dConcComp = asset.ConcreteCompression;
}
}
}
}
}
这里,PropertySetElement 保存的内容是 StructuralAsset
,另外也可以保存 ThermalAsset
。
获取材质的热属性相关例子:
private void ReadMaterialThermalProps(Document document, Material material)
{
ElementId thermalAssetId = material.ThermalAssetId;
if (thermalAssetId != ElementId.InvalidElementId)
{
PropertySetElement pse = document.GetElement(thermalAssetId) as PropertySetElement;
if (pse != null)
{
ThermalAsset asset = pse.GetThermalAsset();
// Check the thermal material type and only read if solid
if (asset.ThermalMaterialType == ThermalMaterialType.Solid)
{
// Get the properties which are supported in solid type
bool isTransmitsLight = asset.TransmitsLight;
double permeability = asset.Permeability;
double porosity = asset.Porosity;
double reflectivity = asset.Reflectivity;
double resistivity = asset.ElectricalResistivity;
StructuralBehavior behavior = asset.Behavior;
// Get the other properties.
double heatOfVaporization = asset.SpecificHeatOfVaporization;
double emissivity = asset.Emissivity;
double conductivity = asset.ThermalConductivity;
double density = asset.Density;
}
}
}
}
通过 API 编辑外观属性:AppearanceAssetEditScope
private void SetDiffuseColor(Material material, Color color)
{
ElementId appearanceAssetId = material.AppearanceAssetId;
AppearanceAssetElement assetElem = material.Document.GetElement(appearanceAssetId) as AppearanceAssetElement;
using (Transaction t = new Transaction(assetElem.Document, "Change material color"))
{
t.Start();
using (AppearanceAssetEditScope editScope = new AppearanceAssetEditScope(assetElem.Document))
{
Asset editableAsset = editScope.Start(assetElem.Id);
AssetPropertyDoubleArray4d genericDiffuseProperty = editableAsset.FindByName("generic_diffuse") as AssetPropertyDoubleArray4d;
genericDiffuseProperty.SetValueAsColor(color);
editScope.Commit(true);
}
t.Commit();
}
}