revit 二次开发 读取材料的信息

用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;
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值