zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    kolla多节点部署openstack
    归并排序
    gitlab ci/cd
    微信、支付宝个人收款码不能用于经营收款 z
    微信小程序弹出和隐藏遮罩层动画以及五星评分
    centos7 安装 nginx
    netty+websocket模式下token身份验证遇到的问题
    windows 截图 win+shift+s
    linux下 "chmod 777" 中777这个数字是怎么出来的
    nginx四层转发,访问内网mysql数据库
  • 原文地址:https://www.cnblogs.com/greatverve/p/revit-api-line-SetComparisonResult.html
Copyright © 2011-2022 走看看