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