12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- /*-------------------------------------------------------------------------
- * 功能描述: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
- {
- /// <summary>
- /// UIDocument 相关扩展信息
- /// </summary>
- public static class UIDocumentExtension
- {
- /// <summary>
- /// 获取当前选中元素
- /// </summary>
- /// <param name="uiDocument"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 获取选中元素
- /// </summary>
- /// <param name="uiDocument"></param>
- /// <returns></returns>
- public static List<Element> GetSelectedElements(this UIDocument uiDocument)
- {
- List<Element> selectedElements = new List<Element>();
- 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;
- }
- }
- }
|