revit 二次开发 读取材料的信息
2017-03-05 21:54
316 查看
用lookup查看材料很具有误导性。
找半天才找出原因,要想找到全部材料必须通过CompoundStructureLayer来查找。
附上代码(两种找材料的方式):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
namespace 读取材料
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Document revitDoc = commandData.Application.ActiveUIDocument.Document; //取得文档
Application revitApp = commandData.Application.Application; //取得应用程序
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Selection sel = uiDoc.Selection;
Reference ref1 = sel.PickObject(ObjectType.Element, "选择一个族实例");
Element elem = revitDoc.GetElement(ref1);
Wall wall = elem as Wall;
ICollection<ElementId> matId = elem.GetMaterialIds(true);
#region 从elementId中获得材料,这种方法获得的是主材
//foreach (var item in matId)
//{
// TaskDialog.Show("REVIT", item.ToString());
// Material mat2 = revitDoc.GetElement(item) as Material; //从elementId中获得材料
//}
#endregion
#region 从CompoundStructureLayer中获得材料,这种方法可以获得与该元素相关的全部材料
WallType wallType = wall.WallType;
CompoundStructure compoundStructure = wallType.GetCompoundStructure();
IList<CompoundStructureLayer> layers = compoundStructure.GetLayers();
foreach(var item in layers)
{
TaskDialog.Show("revit",item.MaterialId.ToString());
}
#endregion
return Result.Succeeded;
}
}
}
找半天才找出原因,要想找到全部材料必须通过CompoundStructureLayer来查找。
附上代码(两种找材料的方式):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
namespace 读取材料
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Document revitDoc = commandData.Application.ActiveUIDocument.Document; //取得文档
Application revitApp = commandData.Application.Application; //取得应用程序
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Selection sel = uiDoc.Selection;
Reference ref1 = sel.PickObject(ObjectType.Element, "选择一个族实例");
Element elem = revitDoc.GetElement(ref1);
Wall wall = elem as Wall;
ICollection<ElementId> matId = elem.GetMaterialIds(true);
#region 从elementId中获得材料,这种方法获得的是主材
//foreach (var item in matId)
//{
// TaskDialog.Show("REVIT", item.ToString());
// Material mat2 = revitDoc.GetElement(item) as Material; //从elementId中获得材料
//}
#endregion
#region 从CompoundStructureLayer中获得材料,这种方法可以获得与该元素相关的全部材料
WallType wallType = wall.WallType;
CompoundStructure compoundStructure = wallType.GetCompoundStructure();
IList<CompoundStructureLayer> layers = compoundStructure.GetLayers();
foreach(var item in layers)
{
TaskDialog.Show("revit",item.MaterialId.ToString());
}
#endregion
return Result.Succeeded;
}
}
}
相关文章推荐
- ABAQUS二次开发悬臂梁以及ODB文件信息的读取
- Revit开发之读取几何信息
- Revit 二次开发 获取明细表中的过滤条件信息
- Revit 二次开发获取元素的材质和外观信息以及贴图
- Revit二次开发——读取构件的材料外观信息
- Revit开发读取CAD信息
- Building Coder(Revit 二次开发) - 参数访问和计划信息
- Revit 二次开发之“通过连接器找到所属元素”
- Revit 2011 二次开发入门
- Revit 2011 二次开发之Ribbon
- Revit 二次开发之“在机械设备之间创建机械系统”
- Revit 二次开发之“参数”
- 想写点Revit 二次开发方面的点滴
- Revit 二次开发之“在两个机械设备之间创建风管”
- 国内Revit二次开发热情高涨,Revit二次开发程序员会成为抢手人才!
- Building Coder(Revit 二次开发)- 在新建族中进行镜像操作,并切换当前视图
- Revit 2012 二次开发最新API网络课程录像下载
- 分享立陶宛的Revit插件,分析国外二次开发产品为什么多?
- 初学编程者开始Revit 二次开发自学教程
- Revit 二次开发之“创建外部应用”