/*-------------------------------------------------------------------------
* 功能描述:UIDocumentExtension
* 作者:xulisong
* 创建时间: 2019/5/23 11:22:36
* 版本号:v1.0
* -------------------------------------------------------------------------*/
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FWindSoft.Revit
{
///
/// UIDocument 相关扩展信息
///
public static class UIDocumentExtension
{
///
/// 获取当前选中元素
///
///
///
public static Element GetSelectedElement(this UIDocument uiDocument)
{
Element selected = null;
UIDocument doc = uiDocument;
var useId = doc.Selection.GetElementIds().FirstOrDefault();
if (useId != null)
{
selected = doc.Document.GetElement(useId);
}
return selected;
}
///
/// 获取选中元素
///
///
///
public static List GetSelectedElements(this UIDocument uiDocument)
{
List selectedElements = new List();
UIDocument uiDoc = uiDocument;
var useIds = uiDoc.Selection.GetElementIds();
if (useIds!=null)
{
var doc = uiDoc.Document;
selectedElements = useIds.Select(id=>doc.GetElement(id)).ToList();
}
return selectedElements;
}
}
}