Revit API多选多重过滤
过滤条件可以这样累加,小技巧。
from:http://revit.5d6d.com/thread-1330-1-1.html
//墙风管过滤器
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;
}
}
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;
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。