Revit API获得材质参数值

通过Materials类来管理材质

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
{
    [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    
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);
        }
    }

}
from:http://revit.5d6d.com/thread-1293-1-1.html
posted @ 2011-10-21 10:51  大气象  阅读(2476)  评论(0编辑  收藏  举报
http://www.tianqiweiqi.com