REVIT二次开发学习笔记2:如何在Revit中创建墙

备注:学习自博主黑夜の骑士REVIT二次开发入门教程

1、老规矩,新建一个类库,实现IExternalCommand接口

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace LearnFilter {
    [Transaction(TransactionMode.Manual)]
    public class CreateWallDemo : IExternalCommand {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) {
            return Result.Succeeded;
        }
    }
}

2、获取当前文档,这里以CW 102-50-100p这个族类型为例,获取该墙类型,将返回值转换为WallType类型。

            //获取当前文档
            Document doc = commandData.Application.ActiveUIDocument.Document;

            //获取CW 102-50-100p类型的墙
            FilteredElementCollector collector = new FilteredElementCollector(doc);
            WallType wallType = collector.OfCategory(BuiltInCategory.OST_Walls).OfClass(typeof(WallType)).FirstOrDefault(x => x.Name == "CW 102-50-100p") as WallType;

3、revit中创建墙的时候需要指定楼层平面的标高,这里获取你要创建墙的标高信息


            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(30, 0, 0);
            Line geomLine = Line.CreateBound(start, end);

5、设置墙的高度和偏移等属性,由于revit的底层是以英寸为单位的,需要将英寸转换为米


            double height = 15 / 0.3048;
            double offset = 0;

6、创建墙

            Transaction trans = new Transaction(doc, "创建墙");
            trans.Start();
            Wall wall = Wall.Create(doc, geomLine, wallType.Id, level.Id, height, offset, false, false);
            trans.Commit();

7、右键程序集生成dll文件,并利用外部工具在revit中载入,就可以看到创建出来的墙了

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值