Revit API多选多重过滤

过滤条件可以这样累加,小技巧。
// 墙风管过滤器
class WallDuctSelectionFilter : ISelectionFilter
{
     public  bool AllowElement(Element e)
    {
         return (e  is Wall) || (e  is Duct);
    }

     public  bool AllowReference(Reference r, XYZ p)
    {
         return  true;
    }
}
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public  class cmdTest20110907 : IExternalCommand
{
     public Result Execute(ExternalCommandData cmdData,  ref  string messages, ElementSet elements)
    {
        UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
        Selection sel = uiDoc.Selection;

        Transaction ts =  new Transaction(uiDoc.Document,  " 多类别多选 ");
        ts.Start();

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

        IList<Reference> listRef = sel.PickObjects(ObjectType.Element,  new WallDuctSelectionFilter(),  " 选择墙和风管 ");
         foreach (Reference refObj  in listRef)
        {
            Element el = uiDoc.Document.GetElement(refObj);
             if (el  is Wall)
            {
                listWall.Add(el  as Wall);
            }
             else  if (el  is Duct)
            {
                listDuct.Add(el  as Duct);
            }
        }
        TaskDialog.Show( " info "" 墙: " + listWall.Count +  " \n风管: " + listDuct.Count);

        ts.Commit();
         return Result.Succeeded;
    }
}
from: http://revit.5d6d.com/thread-1330-1-1.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值