Revit二开--实现管道延长命令

Revit二开实现管道延长

这是在唐僧课堂(http://bimdp.ke.qq.com )的经典案例中讲的一个功能,有部分朋友对其中内容有疑问,现将全部源码在这里公开,并对部分难点做简要说明。

1.封装工具类 DebugUtils
此工具类的作用是 将已知管道的端点延长至 鼠标选择点

 public static class DebugUtils
    {
        public static void ExtendPipe(Pipe p)
        {
            Document doc = p.Document;
            UIDocument uidoc = new UIDocument(doc);
            Selection sel = uidoc.Selection;

            XYZ point = sel.PickPoint();

            LocationCurve lc = p.Location as LocationCurve;

            Line l = lc.Curve as Line;

            XYZ endpoint1 = null;

            if (l.GetEndPoint(0).DistanceTo(point)<l.GetEndPoint(1).DistanceTo(point))
            {
                endpoint1 = l.GetEndPoint(1);
            }
            else
            {
                endpoint1 = l.GetEndPoint(0);
            }

            Transaction ts = new Transaction(doc, "延长管线");
            ts.Start();
            lc.Curve = Line.CreateBound(endpoint1, point);
            ts.Commit();
        }
    }

2.命令类

namespace Revit工具
{
    [Transaction(TransactionMode.Manual)]
    class ExtendCmd :IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData,ref string message,ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Document doc = uidoc.Document;
            Selection sel = uidoc.Selection;

            Pipe pipe = sel.PickObject(ObejctType.Element,"选择一个管道").GetElement(doc) as Pipe;
            DebugUtils.ExtendPipe(pipe);
        }
    }
}

其中GetElement是reference的扩展方法,可以用doc.GetElement(reference.Id) 替代。

详细视频尽在唐僧课堂 qq群:166072827

在这里插入图片描述

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值