Revit API判断直线相交关系移动风管

start
// 风管对齐
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public  class cmdDuctAlign : IExternalCommand
{
     private XYZ GetIntersection(Line line1, Line line2)
    {
        IntersectionResultArray results;

        SetComparisonResult result
            = line1.Intersect(line2,  out results);
         // SetComparisonResult.Subset
        
// SetComparisonResult.Superset 
         if (SetComparisonResult.Overlap == result) // 没有交点,可能是平行,也可以是延长线相交。
             throw  new InvalidOperationException(
                 " Overlap ");
         if (SetComparisonResult.Disjoint == result) // 不相交
             throw  new InvalidOperationException(
                 " Disjoint ");
         if (SetComparisonResult.Superset == result) // 包含,子集
             throw  new InvalidOperationException(
                 " Superset ");
         if (SetComparisonResult.Subset == result) // 交集
             throw  new InvalidOperationException(
                 " Subset ");
         if (results ==  null || results.Size !=  1)
             throw  new InvalidOperationException(
                 " Could not extract line intersection point. ");

        IntersectionResult iResult
            = results.get_Item( 0);

         return iResult.XYZPoint;
    }
     public Result Execute(ExternalCommandData commandData,  ref  string messages, ElementSet elements)
    {
        UIApplication app = commandData.Application;
        Document doc = app.ActiveUIDocument.Document;
        Selection sel = app.ActiveUIDocument.Selection;

        SplitButtonData splitButtonData =  new SplitButtonData( """");
        PushButton pbtn =  new PushButton();
        RibbonPanel rpanel =  new RibbonPanel();
            

        Transaction ts =  new Transaction(doc,  " revit ");
        ts.Start();

        IList<Reference> refDucts = sel.PickObjects(ObjectType.Element,  " duct ");
        Duct duct1 = doc.GetElement(refDucts.ElementAt( 0))  as Duct;
        Duct duct2 = doc.GetElement(refDucts.ElementAt( 1))  as Duct;
        LocationCurve lCurve1 = duct1.Location  as LocationCurve;
        LocationCurve lCurve2 = duct1.Location  as LocationCurve;
        XYZ xyz11 = lCurve1.Curve.get_EndPoint( 0);
        XYZ xyz12 = lCurve1.Curve.get_EndPoint( 1);
        XYZ xyz21 = lCurve2.Curve.get_EndPoint( 0);
        XYZ xyz22 = lCurve2.Curve.get_EndPoint( 1);
         // 判断线段相交关系
        Line line1 = Line.get_Bound(xyz11, xyz12);
        Line line2 = Line.get_Bound(xyz21, xyz22);
        GetIntersection(line1, line2);

         #region 风管移动

         // 转化到平面
        XYZ xyz1 =  new XYZ(xyz11.X, xyz11.Y,  0);
        XYZ xyz2 =  new XYZ(xyz12.X, xyz12.Y,  0);
        XYZ xyz3 =  new XYZ(xyz21.X, xyz21.Y,  0);
        XYZ xyz4 =  new XYZ(xyz22.X, xyz22.Y,  0);
         // 找到与直线垂直的向量
        XYZ vec1 = xyz2 - xyz1;
        XYZ zVec =  new XYZ( 001);
        XYZ nVec = vec1.CrossProduct(zVec).Normalize(); // 两条线相交的面对应的向量
        TaskDialog.Show( " vec ", nVec.CrossProduct(zVec).Normalize().ToString());
        lCurve2.Move(nVec);

         #endregion

        ts.Commit();

         return Result.Succeeded;
    }
}
url:  http://greatverve.cnblogs.com/p/revit-api-line-SetComparisonResult.html
参考:
http://revit.haotui.com/thread-171-1-32.html
http://revit.haotui.com/thread-489-1-23.html
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值