Revit开发 - 获取墙默认的类型

    本文演示:获取墙默认的类型,并将其重命名为“自定义类型”。

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace RevitAddin4
{
    [TransactionAttribute(TransactionMode.Manual)]
    public class RevitAddin : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uiDoc = commandData.Application.ActiveUIDocument;
            Document doc = uiDoc.Document;

            ElementId id = doc.GetDefaultElementTypeId(ElementTypeGroup.WallType);
            WallType type = doc.GetElement(id) as WallType;
            if (type == null)
                return Result.Failed;

            using (Transaction tr = new Transaction(doc))
            {
                tr.Start("重命名类型");
                type.Name = "自定义墙类型";
                tr.Commit();
            }
            return Result.Succeeded;
        }
    }
}

    执行结果:

  Revit开发 - 获取墙默认的类型