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 != )
            throw new InvalidOperationException(
                "Could not extract line intersection point.");         IntersectionResult iResult
            = results.get_Item();         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()) as Duct;
        Duct duct2 = doc.GetElement(refDucts.ElementAt()) as Duct;
        LocationCurve lCurve1 = duct1.Location as LocationCurve;
        LocationCurve lCurve2 = duct1.Location as LocationCurve;
        XYZ xyz11 = lCurve1.Curve.get_EndPoint();
        XYZ xyz12 = lCurve1.Curve.get_EndPoint();
        XYZ xyz21 = lCurve2.Curve.get_EndPoint();
        XYZ xyz22 = lCurve2.Curve.get_EndPoint();
        //判断线段相交关系
        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, );
        XYZ xyz2 = new XYZ(xyz12.X, xyz12.Y, );
        XYZ xyz3 = new XYZ(xyz21.X, xyz21.Y, );
        XYZ xyz4 = new XYZ(xyz22.X, xyz22.Y, );
        //找到与直线垂直的向量
        XYZ vec1 = xyz2 - xyz1;
        XYZ zVec = new XYZ(, , );
        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

Revit API判断直线相交关系移动风管的更多相关文章

  1. POJ 1269 Intersecting Lines (判断直线位置关系)

    题目链接:POJ 1269 Problem Description We all know that a pair of distinct points on a plane defines a li ...

  2. [poj] 1066 Treasure Hunt || 判断直线相交

    原题 在金字塔内有一个宝藏p(x,y),现在要取出这个宝藏. 在金字塔内有许多墙,为了进入宝藏所在的房间必须把墙炸开,但是炸墙只能炸每个房间墙的中点. 求将宝藏运出城堡所需要的最小炸墙数. 判断点和直 ...

  3. Revit API 判断一个构件在某个视图中的可见性

    查看 Revit API.发现有Element::IsHidden这个方法.通过UI创建一个element,注意要使得这个element在某些视图可见,但是在另一些视图不可见.运行下面的方法,你会发现 ...

  4. poj3449(判断直线相交)

    题目链接:https://vjudge.net/problem/POJ-3449 题意:给出若干几何体,判断每个几何体与其它几何体的相交情况,并依次输出. 思路: 首先要知道的是根据正方形对角线的两个 ...

  5. POJ 1269 Intersecting Lines【判断直线相交】

    题意:给两条直线,判断相交,重合或者平行 思路:判断重合可以用叉积,平行用斜率,其他情况即为相交. 求交点: 这里也用到叉积的原理.假设交点为p0(x0,y0).则有: (p1-p0)X(p2-p0) ...

  6. Revit API判断是不是柱族模板

    OwnerFamily即族模板.获取类别的方法:Document.Settings.Categories.get_Item(BuiltInCategory.OST_Columns); //判断是不是柱 ...

  7. CC34:判断直线相交

    题目 解法 水题,判断斜率.判断截距,ok..... class CrossLine { public: bool checkCrossLine(double s1, double s2, doubl ...

  8. poj 1127(直线相交+并查集)

    Jack Straws Description In the game of Jack Straws, a number of plastic or wooden "straws" ...

  9. poj 1269 Intersecting Lines(直线相交)

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8637   Accepted: 391 ...

随机推荐

  1. Hibernate二级缓存(未完待续)

    1.Hibernate的cache介绍: Hibernate实现了良好的Cache机制,可以借助Hibernate内部的Cache迅速提高系统的数据读取性能.Hibernate中的Cache可分为两层 ...

  2. C#并行计算 Parallel.Foreach&Parallel.For

    Parallel.For(int fromInclude, int toExclude, Action<int> body) 栗子: Parallel.For(0, 10, (i) =&g ...

  3. 【译】在Asp.Net Core 中使用外部登陆(google、微博...)

    原文出自Rui Figueiredo的博文<External Login Providers in ASP.NET Core> (本文很长) 摘要:本文主要介绍了使用外部登陆提供程序登陆的 ...

  4. springboot创建一个可执行的jar

    让我们通过创建一个完全自包含的可执行jar文件来结束我们的示例,该jar文件可以在生产环境运行.可执行jars(有时候被成为胖jars "fat jars")是包含你的编译后的类和 ...

  5. Project Euler Problem1

    Multiples of 3 and 5 Problem 1 If we list all the natural numbers below 10 that are multiples of 3 o ...

  6. 使用netperf测试网络性能

    1.安装netperf 1)获取netperf安装包 netperf-2.7.0.tar.bz2 2)解压到本地目录 3)进入netperf-2.7.0,执行:./configure 4)编译执行:m ...

  7. three.js 初探

    2014年3月3日 22:18:40 简单旋转立方体: http://blog.163.com/hailin_xin/blog/static/21816219020136103402812 简单球体入 ...

  8. SSL邮件发送(腾讯企业邮箱测试通过,可以支持多附件)

    参考网址:http://www.cnblogs.com/LUA123/p/5575134.html ,谢谢! package net.common.utils.common; import java. ...

  9. Java 抽象类和抽象方法

    包含抽象方法的类叫抽象类,如果一个类中包含一个或多个抽象方法,该类必须被限定为抽象的,否则编译器会报错,抽象类不可创建对象,创建抽象类的对象编译器会报错 如果从一个抽象类继承,并想创建该新类的对象,那 ...

  10. ASP.Net1

    一.Web应用程序与传统桌面应用程序的不同: 1.产品级的Web应用程序总是包括至少两台联网的机器:一台承载网站,另一台在Web浏览器中查看数据. 即:我们通过自己的电脑浏览Web程序,这个程序会向服 ...