这篇随笔呢就对Revit开发中的Selection做一个总结吧。Selection顾名思义就是“选中”的意思。
You can get the selected objects from the current active document using the
UIDocument.Selection.Elements property. The selected objects are in an
ElementSet in Revit. From
this Element set, all selected Elements are
retrieved. The Selection object can also be used to
change the current
selection programmatically.
The Selection class also has methods for allowing the user to select new
objects, or even a point on
screen. This allows the user to select one or
more Elements (or other objects, such as an edge or
a face) using the cursor
and then returns control to your application. These functions do not
automatically add the new selection to the active selection collection.
在当前视图中选中对象的方式有四种:
1.The PickObject() method prompts the user to select an object in the Revit model. //选中一个对象
2.The PickObjects() method prompts the user to select multiple objects in the Revit model. //选中多个对象
3.The PickElementsByRectangle() method prompts the user to select multiple elements using a rectangle. //框选多个对象
4.The PickPoint() method prompts the user to pick a point in the active sketch plane.//选中一个点
下面是一个代码示例:
public static IList<Element> GetManyRefByRectangle(UIDocument doc) { ReferenceArray ra = new ReferenceArray(); ISelectionFilter selFilter = new MassSelectionFilter();//过滤类,项目中经常把需要过滤的条件封装成一个类 IList<Element> eList = doc.Selection.PickElementsByRectangle(selFilter, "Select multiple faces") as IList<Element>; return eList; }
///
//分装的过滤类
/// public class MassSelectionFilter : ISelectionFilter { public bool AllowElement(Element element) { if (element.Category.Name == "Mass")//过滤的条件 { return true; } return false; } public bool AllowReference(Reference refer, XYZ point) { return false; } }
Revit 中的Selection,布布扣,bubuko.com
原文:http://www.cnblogs.com/love-huihui-zhupo/p/3578228.html