1.创建类库项目(自行命名)
2.添加引用信息
3.代码部分4
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CreateWallDemo
{
[Transaction(TransactionMode.Manual)]
public class FirstDemo_CreateWall : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//【1】获取当前文档
Document doc = commandData.Application.ActiveUIDocument.Document;
//【2】获取CW 102-50-100墙的族类型
FilteredElementCollector fel = new FilteredElementCollector(doc);
WallType wallType = fel.OfCategory(BuiltInCategory.OST_Walls).OfClass(typeof(WallType))
.FirstOrDefault(x => x.Name == "CW 102-50-100p") as WallType;
//【3】获取标高
Level level = new FilteredElementCollector(doc).OfClass(typeof(Level)).FirstOrDefault(x => x.Name == "标高 1") as Level;
//【4】创建线
XYZ start = new XYZ(0, 0, 0);
XYZ end = new XYZ(10, 10, 0);
Line line = Line.CreateBound(start, end);
//无连接高度
double height = 30 / 0.3048;
double offset = 0;
//【5】创建事务
Transaction trans = new Transaction(doc,"创建墙");
trans.Start();
Wall wall = Wall.Create(doc, line, wallType.Id, level.Id, height, offset, false, false);
trans.Commit();
return Result.Succeeded;
}
}
}
4.运行代码,复制生成的dll文件路径
5.在revit中加载复制的dll文件,效果如下