Revit API: 材质- 参考官方文档(一)

前言

自己研究了一圈材质之后,在官方文档里面翻了一下,发现也有一些介绍,整理一下。
我研究的参考:Revit API: Material 材质

内容

下面按照官方的文档做个整理。

材质基本信息

链接:General Material Information
材质的属性:一个材质包含一个或多个和渲染相关的内容,比如外观、结构等。每一个部分都会有一系列的属性来描述,这些属性被称为资源 assetsStructuralAsset 表示该材质和结构相关的属性。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 材质
下面讲讲 StructuralAssetIdThermalAssetId,主要的属性是在类 Autodesk.Revit.DB.StructuralAssetAutodesk.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();
   }
}

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

极客BIM工作室

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值