BIM建筑网
更专业的BIM技术学习网站!


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

VIP免费下载全站资源
VIP优惠来袭,免费下载全站资料和课程,技术问题可以随时提问;
查看VIP会员

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

微信公众号:xuebim
关注建筑行业BIM发展、研究建筑新技术,汇集建筑前沿信息!
← 微信扫一扫,关注我们+
赞(0) 打赏
BIM建筑网 » revit 二次开发 读取材料的信息
100套内部BIM资料,限时领!
付费搞来的,大家都在学!
领取资料 AI解答

评论 抢沙发

评论前必须登录!

 

BIM建筑网,更专业的BIM技术学习网站!

关注建筑新动态,分享建筑新技术

联系我们关于BIM建筑网

觉得文章有用就打赏一下小编吧

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

扫码登录

微信「关注」,快捷登录
扫码关注后会自动登录
注册登录代表您已同意《用户许可协议》
账号登录 | 其他登录

|登录

找回密码

|账号登录注册