Revit API通过相交过滤器找到与风管相交的对象。

相交过滤器的应用,比几何相交法简便。 Excluding剔除
// 找到与风管相交的对象,通过相交过滤器。
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public  class FindIntersectWallsByElement : IExternalCommand
{
     public Result Execute(ExternalCommandData commandData,  ref  string messages, ElementSet elements)
    {
        UIApplication app = commandData.Application;
        Document doc = app.ActiveUIDocument.Document;
        Transaction trans =  new Transaction(doc,  " ExComm ");
        trans.Start();

         // pick the duct
        Selection sel = app.ActiveUIDocument.Selection;
        Reference ref1 = sel.PickObject(ObjectType.Element,  " Please pick a duct ");
        Element duct = doc.GetElement(ref1);

        FilteredElementCollector collector =  new FilteredElementCollector(doc);
         // 相交过滤器
        ElementIntersectsElementFilter elementFilter =  new ElementIntersectsElementFilter(duct,  false);
        collector.WherePasses(elementFilter);

        List<ElementId> excludes =  new List<ElementId>();
        excludes.Add(duct.Id);
        collector.Excluding(excludes); // 剔除自身

        sel.Elements.Clear();

         // Add these interseting element to the selection
         foreach (Element elem  in collector)
        {
            sel.Elements.Add(elem);
        }

        trans.Commit();
         return Result.Succeeded;
    }
}
url: http://greatverve.cnblogs.com/p/ElementIntersectsElementFilter.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值