Revit API获得材质参数值
通过Materials类来管理材质
from:http://revit.5d6d.com/thread-1293-1-1.html
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);
}
}
}
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);
}
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。