Revit API获得材质参数值
通过Materials类来管理材质
http://images.cnblogs.com/cnblogs_com/greatverve/material.PNG
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WinForm = System.Windows.Forms;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.ExtensibleStorage;
using System.Xml;
namespace RevitCodes
{
public class cmdMaterial : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
Document doc = uiApp.ActiveUIDocument.Document;
Selection sel = uiApp.ActiveUIDocument.Selection;
Transaction ts = new Transaction(doc, "http://revit.5d6d.com");
ts.Start();
//选中一个窗户
Element element = doc.GetElement(sel.PickObject(ObjectType.Element, "请选择个对象"));
FamilyInstance fi = element as FamilyInstance;
GetMaterial(doc, fi);
ts.Commit();
return Result.Succeeded;
}
public void GetMaterial(Document document, FamilyInstance familyInstance)
{
Materials materials = document.Settings.Materials;
string str = "";
foreach (Parameter pa in familyInstance.Symbol.Parameters)//通过族符号
{
Definition definition = pa.Definition;//参数的基类
//过滤参数
if (definition.ParameterGroup == BuiltInParameterGroup.PG_MATERIALS &&
definition.ParameterType == ParameterType.Material)
{
Material ma = materials.get_Item(pa.AsElementId());//得到材料参数值的方法
str += definition.Name + ":" + ma.Name + "\n";
}
}
TaskDialog.Show("材质信息", str);
}
}
}
顶!!!!!!!!!!
页:
[1]