Revit二次开发之 Material 分析

发布时间 2023-07-27 20:38:15作者: Min.Xiaoshuang

对于revit来说,任何Element都可以包含一个或者多个Material,其通过方法:

public ICollection<ElementId> GetMaterialIds(
    bool returnPaintMaterials
)

获取指定元素的材质集合,如果为true,则返回“绘制”工具指定给元素面的材质ID。如果为false,则返回通过材质的几何体或复合结构层与材质关联的id。

Material element =this.Document.GetElement(materialNode.MaterialId) as Material;

通过

GetElement函数获取残值对象

 

对于一个材质,他包含标识、图形、外观、物理、热度等信息。

private void GetMaterialInformation(Material material)
{//对应作色信息
   message.Append(string.Format("\nColor: Red[{0}]; Green[{1}]; Blue[{2}]",
                   material.Color.Red, material.Color.Green, material.Color.Blue));

   //对应表面填充图案---前景
   FillPatternElement cutForegroundPattern = material.Document.GetElement(material.CutForegroundPatternId) as FillPatternElement;
   if (null != cutForegroundPattern)
   {
      message.Append("\nCut Foreground Pattern: " + cutForegroundPattern.Name);
      message.Append(string.Format("\nCut Foreground Pattern Color: Red[{0}]; Green[{1}]; Blue[{2}]",
                      material.CutForegroundPatternColor.Red, material.CutForegroundPatternColor.Green, material.CutForegroundPatternColor.Blue));
   }

   //对应表面填充图案--背景
   FillPatternElement surfaceForegroundPattern = material.Document.GetElement(material.SurfaceForegroundPatternId) as FillPatternElement;
   if (null != surfaceForegroundPattern)
   {
      message.Append("\nSurface Foreground Pattern: " + surfaceForegroundPattern.Name);
      message.Append(string.Format("\nSurface Foreground Pattern Color: Red[{0}]; Green[{1}]; Blue[{2}]",
                      material.SurfaceForegroundPatternColor.Red, material.SurfaceForegroundPatternColor.Green, material.SurfaceForegroundPatternColor.Blue));
   }

   //界面填充图案,背景
   FillPatternElement cutBackgroundPattern = material.Document.GetElement(material.CutBackgroundPatternId) as FillPatternElement;
   if (null != cutBackgroundPattern)
   {
      message.Append("\nCut Background Pattern: " + cutBackgroundPattern.Name);
      message.Append(string.Format("\nCut Background Pattern Color: Red[{0}]; Green[{1}]; Blue[{2}]",
                      material.CutBackgroundPatternColor.Red, material.CutBackgroundPatternColor.Green, material.CutBackgroundPatternColor.Blue));
   }

   //background surface pattern and pattern color of the material
   FillPatternElement surfaceBackgroundPattern = material.Document.GetElement(material.SurfaceBackgroundPatternId) as FillPatternElement;
   if (null != surfaceBackgroundPattern)
   {
      message.Append("\nSurface Background Pattern: " + surfaceBackgroundPattern.Name);
      message.Append(string.Format("\nSurface Background Pattern Color: Red[{0}]; Green[{1}]; Blue[{2}]",
                      material.SurfaceBackgroundPatternColor.Red, material.SurfaceBackgroundPatternColor.Green, material.SurfaceBackgroundPatternColor.Blue));
   }

   //some shading property of the material
   int shininess = material.Shininess;
   message.Append("\nShininess: " + shininess);
   int smoothness = material.Smoothness;
   message.Append("\nSmoothness: " + smoothness);
   int transparency = material.Transparency;
   message.Append("\nTransparency: " + transparency);

   TaskDialog.Show("Revit", message.ToString());
}