Revit二次开发小白学习笔记3——Revit的Selection操作交互
- 说明:Selection可以获取鼠标选中的Revit要素
1.uIDocument.Selection.PickObject():选取单个要素
Reference reference = uIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
Element element = document.GetElement(reference);
TaskDialog.Show("选中元素ID",element.Id.IntegerValue.ToString() + ":" + element.Name);
2.uIDocument.Selection.PickObjects():选取多个要素
public class DoorFilter : ISelectionFilter
{
public bool AllowElement(Element elem)
{
{
if ((elem is FamilyInstance) && (elem.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Doors))
return true;
}
return false;
}
public bool AllowReference(Reference reference, XYZ position)
{
throw new NotImplementedException();
}
}
IList< Reference > list_Reference = uIDocument.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element,new DoorFilter());
StringBuilder stringBuilder = new StringBuilder();
foreach (Reference item in list_Reference)
{
Element elem = document.GetElement(item);
stringBuilder.AppendLine(elem.Name + ":" + elem.Id.IntegerValue.ToString());
}
TaskDialog.Show("多选对象",stringBuilder.ToString());
3.uIDocument.Selection.PickPoint():选取点坐标
XYZ xyz = uIDocument.Selection.PickPoint();
TaskDialog.Show("选取点",xyz+"");