Revit开发 - 创建幕墙系统(CurtainSystem)

本文演示Revit中创建幕墙系统。

1.用Revit绘制模型

Revit开发 - 创建幕墙系统(CurtainSystem)_第1张图片

2.实例代码

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

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;
            //选择一个面
            Selection selection = uiDoc.Selection;
            Reference reference = selection.PickObject(ObjectType.Face);
            Element element = doc.GetElement(reference);
            Face face = element.GetGeometryObjectFromReference(reference) as Face;
            if (face == null)
            {
                TaskDialog.Show("错误", "不是Face");
                return Result.Failed;
            }
            FaceArray faceArray = new FaceArray();
            faceArray.Append(face);
            //获取幕墙系统的默认类型
            CurtainSystemType type = doc.GetElement(doc.GetDefaultElementTypeId(ElementTypeGroup.CurtainSystemType))as CurtainSystemType;
            if (type == null)
            {
                TaskDialog.Show("错误", "不是CurtainSystemType");
                return Result.Failed;
            }
            //在事务中创建幕墙系统
            using (Transaction tr = new Transaction(doc))
            {
                tr.Start("Create CurtainSystem");
                doc.Create.NewCurtainSystem(faceArray,type);
                tr.Commit();
            }         
            return Result.Succeeded;
        }
    }
}

    运行结果:

 Revit开发 - 创建幕墙系统(CurtainSystem)_第2张图片

你可能感兴趣的:(Revit)