start

[Transaction(TransactionMode.Manual)]

[Regeneration(RegenerationOption.Manual)]

public class cmdDuctWall : IExternalCommand

{

    public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)

    {

        UIApplication uiApp = cmdData.Application;

        UIDocument uiDoc = cmdData.Application.ActiveUIDocument;

        Document doc = uiDoc.Document;

        Selection sel = uiDoc.Selection;

        Transaction ts = new Transaction(uiDoc.Document, "delete");

        ts.Start();

        //加载链接文件

        FilteredElementCollector collector = new FilteredElementCollector(doc);//

        collector.OfClass(typeof(Instance)).OfCategory(BuiltInCategory.OST_RvtLinks);//RevitLinkType

        List<string> listPath = GetLinkFilePaths(doc);

        Duct duct = doc.GetElement(sel.PickObject(ObjectType.Element, "duct")) as Duct;

        foreach (Element elDoc in collector)

        {

            Instance ins = elDoc as Instance;

            if (ins != null)

            {

                Transform transForm = ins.GetTransform();

                string strKey = elDoc.Name.Substring(, elDoc.Name.IndexOf(".rvt"));//找到链接文件名称

                string strPath = GetLinkPath(listPath, strKey);

                Document docLink = uiApp.Application.OpenDocumentFile(strPath);

                List<Wall> listWall = FindDuctWall(doc, duct, docLink, ins.GetTransform().Origin);

                TaskDialog.Show("count", listWall.Count.ToString());

                List<Wall> listWall1 = FindDuctWall(doc, duct);

                TaskDialog.Show("count", listWall1.Count.ToString());

            }

        }

        ts.Commit();

        return Result.Succeeded;

    }

    /// <summary>

    /// 找到当前文档穿过的墙

    /// </summary>

    /// <param name="doc"></param>

    /// <param name="duct"></param>

    /// <returns></returns>

    public List<Wall> FindDuctWall(Document doc, Duct duct)

    {

        List<Wall> listWall = new List<Wall>();

        //找到outLine

        BoundingBoxXYZ bb = duct.get_BoundingBox(doc.ActiveView);

        Outline outline = new Outline(bb.Min, bb.Max);

        //WinFormTools.MsgBox(bb.Min + "|" + bb.Max);

        //

        FilteredElementCollector collector = new FilteredElementCollector(doc);

        BoundingBoxIntersectsFilter invertFilter = new BoundingBoxIntersectsFilter(outline, false);

        IList<Element> noIntersectWalls = collector.OfClass(typeof(Wall)).WherePasses(invertFilter).ToElements();

        foreach (Element el in noIntersectWalls)

        {

            Wall wall = el as Wall;

            if (wall != null)

                listWall.Add(wall);

        }

        return listWall;

    }

    /// <summary>

    /// 找到穿过链接文件的墙

    /// </summary>

    /// <param name="doc"></param>

    /// <param name="duct"></param>

    /// <param name="docLink"></param>

    /// <param name="xyz">依稀量</param>

    /// <returns></returns>

    public List<Wall> FindDuctWall(Document doc, Duct duct, Document docLink, XYZ xyz)

    {

        List<Wall> listWall = new List<Wall>();

        //找到outLine

        BoundingBoxXYZ bb = duct.get_BoundingBox(doc.ActiveView);

        Outline outline = new Outline(bb.Min - xyz, bb.Max - xyz);

        //

        FilteredElementCollector collector = new FilteredElementCollector(docLink);

        BoundingBoxIntersectsFilter invertFilter = new BoundingBoxIntersectsFilter(outline, false);

        IList<Element> noIntersectWalls = collector.OfClass(typeof(Wall)).WherePasses(invertFilter).ToElements();

        foreach (Element el in noIntersectWalls)

        {

            Wall wall = el as Wall;

            if (wall != null)

                listWall.Add(wall);

        }

        return listWall;

    }

    /// <summary>

    /// 取得链接文件路径

    /// </summary>

    /// <param name="doc"></param>

    /// <returns></returns>

    public List<string> GetLinkFilePaths(Document doc)

    {

        List<string> listPath = new List<string>();

        foreach (ElementId elId in ExternalFileUtils.GetAllExternalFileReferences(doc))

        {

            if (doc.get_Element(elId).IsExternalFileReference())

            {

                ExternalFileReference fileRef = doc.get_Element(elId).GetExternalFileReference();

                if (ExternalFileReferenceType.RevitLink == fileRef.ExternalFileReferenceType)

                    listPath.Add(ModelPathUtils.ConvertModelPathToUserVisiblePath(fileRef.GetAbsolutePath()));

            }

        }

        return listPath;

    }

    /// <summary>

    /// 根据链接文件名称找到对应链接路径,模糊匹配,待改进

    /// </summary>

    /// <param name="listPath"></param>

    /// <param name="strKey"></param>

    /// <returns></returns>

    public string GetLinkPath(List<string> listPath, string strKey)

    {

        foreach (string strPath in listPath)

        {

            if (strPath.Contains(strKey))

                return strPath;

        }

        return "";

    }

}

url:http://greatverve.cnblogs.com/p/revit-api-ductWall.html

Revit API找到风管穿过的墙(当前文档和链接文档)的更多相关文章

  1. Openstack api 学习文档 & restclient使用文档

    Openstack api 学习文档 & restclient使用文档 转载请注明http://www.cnblogs.com/juandx/p/4943409.html 这篇文档总结一下我初 ...

  2. API接口文档中将Swagger文档转Word 文档

    一般的开发工作,尤其是API接口的开发工作,首先要有开发文档,接口说明文档 ok,后来开发完毕了 和页面联调,或者是和第三方联调的时候, 这个时候,SA systeam admin 就会开始直接让开发 ...

  3. 一个非常适合IT团队的在线API文档、技术文档工具 (ShowDoc)

    在逸橙呆了不到两年,开发时后端都有开发接口API,来到数库,好多后端开发和前端沟通是还是发doc文档,很不方便,我向cto反应,自己找到这个,老乡田雷(php,隔壁村的)也用过,可能某些原因选择其他的 ...

  4. [工具推荐]制作基于Dash的本地文档方便搜索文档api和内容

    [版权声明]:本文章由danvid发布于http://danvid.cnblogs.com/,如需转载或部分使用请注明出处 最近在看es的文档,发现查起api来真的很麻烦,很多现在开源的文档都没有查询 ...

  5. Revit API改变风管及管件尺寸

    start , , )) < , , -)) < , dHeight = ;             ConnectorSetIterator csi = fi.MEPModel.Conn ...

  6. Revit API移动风管

    移动风管曲线就可以移动风管 , , ));//向上移动3         ts.Commit();         return Result.Succeeded;     } } url:http: ...

  7. C# : 操作Word文件的API - (将C# source中的xml注释转换成word文档)

    这篇博客将要讨论的是关于: 如何从C#的source以及注释, 生成一份Word格式的关于各个类,函数以及成员变量的说明文档. 他的大背景如下...... 最近的一个项目使用C#, 分N个模块, 在项 ...

  8. Revit API根据链接文件开洞

    开洞信息数据: ]);             ;                     ;                     ;                     ;          ...

  9. 关于Revit API修改元素参数的问题?

    >ADN: DEVR3894  >ADN service level: Professional  >产品:Revit MEP 2012  >版本:2012  >语言:中 ...

随机推荐

  1. linux 查看有哪些service

    一.利用进程来查看命令里 ps -aux | grep xxx 是查看某个进程或者服务是否存在.二.利用chkconfig配置工具chkconfig --list 可以列出所有的服务在各个runlev ...

  2. ubuntu16.04系统搜狗输入法的安装

    参考博客:https://www.cnblogs.com/lrj567/p/6307329.html 本来不想写的,但是最近老是重装系统,每次百度特别浪费时间,特此记录一下 先去官网下载搜狗输入法li ...

  3. 【干货】查看windows文件系统中的数据—利用簇号查看文件与恢复文件

    前面我们使用这个软件发现了很多删除掉的数据,今天来看看簇.FAT文件系统中,存在一个簇的链接,我知道了簇1在哪里就可以顺藤摸瓜恢复所有的信息. 这里使用FAT 12为例子,FAT其他万变不离其宗,甚至 ...

  4. Implement Queue by Two Stacks & Implement Stack using Queues

    Implement Queue by Two Stacks Implement the following operations of a queue using stacks. push(x) -- ...

  5. shell中后台进程管理: ps -aux 详解

    常用 查找进程id方法:      ps -aux | grep "jupyter"                杀进程:   kill -9 具体的PID 1.ps命令 要对进 ...

  6. Android BLE设备蓝牙通信框架BluetoothKit

    BluetoothKit是一款功能强大的Android蓝牙通信框架,支持低功耗蓝牙设备的连接通信.蓝牙广播扫描及Beacon解析. 关于该项目的详细文档请关注:https://github.com/d ...

  7. python小记

    最近有匹骚猪用微信骚扰我,我很是气愤, 自学一波脚本: 学习目的:用脚本回击回去,通过py写一个脚本,一次性给别人发n条消息: mac上自学python: brew install python3(自 ...

  8. PHP取整函数之ceil,floor,round,intval的区别

    我们经常用到的PHP取整函数,主要是:ceil,floor,round,intval. ceil -- 进一法取整 说明 float ceil ( float value ) 返回不小于 value ...

  9. 关于NOIP2018初赛

    题面 这次PJ初赛有点傻了,可能是因为兴华水土不服吧(在这荒度了六年级的光阴). 选择题 DDDBBAAAABABBBB 第四题 当时懵了,我啥也不知道,于是就开始蒙 A.LAN B.WAN C.MA ...

  10. #Plugin 中国省市选择插件

    中国省市选择插件  ChineseCities 1.原生JS,不依赖jquery,zepto 2.前端学习交流群:814798690 源码查看 点击下载 https://github.com/chao ...