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

0

评论0

请先
16D303-3 常用水泵控制电路图(替代10D303-3图集).pdf
16D303-3 常用水泵控制电路图(替代10D303-3图集).pdf
8分钟前 有人购买 去瞅瞅看

社交账号快速登录

微信扫一扫关注
扫码关注后会自动登录网站