EaBIM一直以来积极响应国家“十二五”推进建筑业信息化的号召,对建筑领域的信息技术开展深入技术交流和探讨!致力于打造“BIM-建筑师-生态技术”三位一体综合资源交流共享平台,希望为BIM与可持续设计理念及技术的普及做出微小的贡献!!!

EaBIM

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 503|回复: 1
打印 上一主题 下一主题

Revit API判断点与线是否相交

[复制链接]

1514

主题

7465

帖子

1万

积分

admin

Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10

积分
12406

社区QQ达人

跳转到指定楼层
楼主
发表于 2014-1-9 13:07:25 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式


曲线有个curve.Distance(xyz)函数用来判断曲线与的距离。[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
  1. <div><font color="#696969" face="Microsoft Yahei, Simsun"></font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">public</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">class cmdXyzLine : IExternalCommand</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">{</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">    public Result Execute(ExternalCommandData commandData, ref</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">string messages, ElementSet elements)</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">    {</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        UIApplication uiApp = commandData.Application;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        Document doc = uiApp.ActiveUIDocument.Document;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        Selection sel = uiApp.ActiveUIDocument.Selection;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">
  2. </font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        Transaction ts =</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">new Transaction(doc, "http://revit.5d6d.com");</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        ts.Start();</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">
  3. </font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        //选取一直线,先风管吧。</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        Duct duct = doc.GetElement(sel.PickObject(ObjectType.Element, "选取一风管")) as Duct;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        //选取一点</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        XYZ xyz = sel.PickPoint("选取一点");</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        //判断是否相交</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        LocationCurve ductCurve = duct.Location as LocationCurve;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        TaskDialog.Show("distance", ductCurve.Curve.Distance(xyz).ToString());</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        if (ductCurve.Curve.Distance(xyz) <</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">0.01)</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">            TaskDialog.Show("info", "相交");</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        else</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">            TaskDialog.Show("info", "不相交");</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        //风管上的点与风管曲线的距离</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        TaskDialog.Show("dis", ductCurve.Curve.Distance(ductCurve.Curve.get_EndPoint(0)).ToString() +</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">"米");</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">
  4. </font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        ts.Commit();</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">
  5. </font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        return Result.Succeeded;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">    }</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">}</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">
  6. </font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">另外一个方法,比较专业,抽时间仔细研究研究:</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">///</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun"><summary></font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">/// 两曲线通过轨迹相同且相连则可合并</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">///</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun"></summary></font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">///</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun"><param name="uiApp"></param></font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">///</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun"><param name="c1"></param></font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">///</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun"><param name="c2"></param></font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">///</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun"><returns></returns></font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">public</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">static Curve Combine2Curve(UIApplication uiApp, Curve c1, Curve c2)</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">{</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">    // 两曲线均为直线</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">    Line l1 = c1 as Line;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">    if (l1 !=</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">null)</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">    {</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        Line l2 = c2 as Line;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        if (l2 !=</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">null)</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        {</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">            XYZ vt1 = LineAssistFunc.GetVector(l1);</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">            XYZ vt2 = LineAssistFunc.GetVector(l2);</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">            // 平行</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">
  7. </font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">if (GeoUtil.IsParallel(vt1, vt2))</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">            {</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                XYZ pts1 = l1.get_EndPoint(0);</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                XYZ pte1 = l1.get_EndPoint(1);</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                XYZ pts2 = l2.get_EndPoint(0);</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                XYZ pte2 = l2.get_EndPoint(1);</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                // 相连</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">
  8. </font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">if (pts1.DistanceTo(pts2) < precision || pts1.DistanceTo(pte2) < precision ||</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    pte1.DistanceTo(pts2) < precision || pte1.DistanceTo(pte2) < precision)</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                {</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    List<XYZ> arPts =</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">new List<XYZ>();</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    arPts.Add(pts1);</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    arPts.Add(pte1);</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    arPts.Add(pts2);</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    arPts.Add(pte2);</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    GeoUtil.SortPointByDirect(uiApp, arPts, vt1);</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">
  9. </font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    Line nLine = uiApp.Application.Create.NewLineBound(arPts.First(), arPts.Last());</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    return nLine;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                }</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">            }</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        }</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">    }</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">
  10. </font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">    // 两曲线均为弧线</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">    Arc a1 = c1 as Arc;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">    if (a1 !=</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">null)</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">    {</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        Arc a2 = c2 as Arc;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        if (a2 !=</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">null)</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        {</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">            double r1 = a1.Radius;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">            double r2 = a2.Radius;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">            XYZ ptc1 = a1.Center;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">            XYZ ptc2 = a2.Center;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">            // 共线</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">
  11. </font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">if (Math.Abs(r1 - r2) < precision && ptc1.DistanceTo(ptc2) < precision)</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">            {</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                XYZ pts1 = a1.get_EndPoint(0);</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                XYZ pte1 = a1.get_EndPoint(1);</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                XYZ pts2 = a2.get_EndPoint(0);</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                XYZ pte2 = a2.get_EndPoint(1);</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                // 相连</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">
  12. </font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">if (pts1.DistanceTo(pts2) < precision || pts1.DistanceTo(pte2) < precision ||</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    pte1.DistanceTo(pts2) < precision || pte1.DistanceTo(pte2) < precision)</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                {</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    // 相交的点为ptOnArc点,其余两点为弧线的起终点</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    XYZ ptStart =</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">null, ptEnd =</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">null, ptOnArc =</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">null;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    if (pts1.DistanceTo(pts2) < precision)</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    {</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                        ptStart = pte1;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                        ptEnd = pte2;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                        ptOnArc = pts1;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    }</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    else</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">if (pts1.DistanceTo(pte2) < precision)</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    {</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                        ptStart = pte1;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                        ptEnd = pts2;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                        ptOnArc = pts1;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    }</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    else</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">if (pte1.DistanceTo(pts2) < precision)</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    {</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                        ptStart = pts1;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                        ptEnd = pte2;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                        ptOnArc = pte1;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    }</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    else</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">if (pte1.DistanceTo(pte2) < precision)</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    {</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                        ptStart = pts1;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                        ptEnd = pts2;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                        ptOnArc = pte1;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    }</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">
  13. </font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    Arc nArc = uiApp.Application.Create.NewArc(ptStart, ptEnd, ptOnArc);</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                    return nArc;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">                }</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">            }</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">        }</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">    }</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">
  14. </font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">    return</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">null;</font></div><div><font color="#696969" face="Microsoft Yahei, Simsun">}</font></div>
复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 转播转播 分享分享 分享淘帖 支持支持 反对反对
工作时间:工作日的9:00-12:00/13:30-18:00,节假日不在线,请勿留言

5

主题

827

帖子

1032

积分

BIM项目负责人

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

积分
1032
2F
发表于 2014-2-20 14:34:01 | 只看该作者
顶...... 楼下跟上.....
*滑块验证:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|EaBIM网 ( 苏ICP备2020058923号-1  苏公网安备32011502011255号

GMT+8, 2024-11-27 18:28

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表