Revit二次开发之 Material 分析
对于revit来说,任何Element都可以包含一个或者多个Material,其通过方法:
public ICollection<ElementId> GetMaterialIds( bool returnPaintMaterials )
获取指定元素的材质集合,如果为true,则返回“绘制”工具指定给元素面的材质ID。如果为false,则返回通过材质的几何体或复合结构层与材质关联的id。
Material element =this.Document.GetElement(materialNode.MaterialId) as Material;
有【标识】、【图形】、【外观】、【物理】和【热度】五个选项卡,而我们最经常设置的就是【图形】和【外观】选项卡。
【图形】决定“着色”模式中材质呈现的外观;
【外观】决定“真实”模式中材质呈现的样式。
一、图形
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)); } //表面背景填充元素 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)); } //其他的一些属性 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()); }
二、外观
外观是材质的一个特性,其通过以下属性获取
Material mat2 = revitDoc.GetElement(item.MaterialId) as Material; ElementId assetElementId = mat2.AppearanceAssetId; if(assetElementId!=ElementId.InvalidElementId) { //获取外观元素 AppearanceAssetElement appearanceAssetElement = revitDoc.GetElement(assetElementId) as AppearanceAssetElement;
Asset currentAsset = appearanceAssetElement.GetRenderingAsset(); }
这里面就有2个重要的类
AppearanceAssetElement 外观对象
Asset 表示材质的连接特性。
Asset 对象,最主要的功能,是记录了大量的AssetProperty对象,AssetProperty其实就是当前材质所有包含的属性
AssetProperty
AssetProperties
AssetPropertyBoolean
AssetPropertyDistance
AssetPropertyDouble
AssetPropertyDoubleArray2d
AssetPropertyDoubleArray3d
AssetPropertyDoubleArray4d
AssetPropertyDoubleMatrix44
AssetPropertyEnum
AssetPropertyFloat
AssetPropertyFloatArray
AssetPropertyInt64
AssetPropertyInteger
AssetPropertyList
AssetPropertyReference
AssetPropertyString
AssetPropertyTime
AssetPropertyUInt64
当前revit通过这些属性的名称和值,来控制材质的特性,大概描述基本如下图:
通过以上分析,我们基本可以得到以下组织结构:
三、获取全部。
当前我们在进行材质赋值的时候,需要读取当前RVT文件中到底有多少材质,可以通过app的get_Assets方法,获取当前RVT文件材质的集合
AssetSet objlibraryAsset = revitApp.get_Assets(AssetType.Appearance);