123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- /*-------------------------------------------------------------------------
- * 功能描述:ApplicationExtension
- * 作者:xulisong
- * 创建时间: 2019/3/12 11:30:00
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Autodesk.Revit.DB;
- using Autodesk.Revit.UI;
- using Autodesk.Revit.UI.Selection;
- namespace FWindSoft.Revit
- {
- public static class ApplicationExtension
- {
- public static Selection GetSelection(this UIApplication app)
- {
- UIDocument doc = app.ActiveUIDocument;
- if (doc != null)
- return doc.Selection;
- return null;
- }
- public static void AddSelectElements(this UIApplication uiApp, List<Element> elements)
- {
- if (elements == null || elements.Count == 0)
- return;
- Selection selection = uiApp.GetSelection();
- if (selection == null) return;
- List<ElementId> idList = selection.GetElementIds().ToList();
- elements.ForEach(p => idList.Add(p.Id));
- selection.SetElementIds(idList);
- }
- public static void ClearSelectElements(this UIApplication uiApp)
- {
- Selection selection = uiApp.GetSelection();
- if (selection == null) return;
- selection.SetElementIds(new List<ElementId>());
- }
- public static void SelectElements(this UIApplication uiApp, List<Element> elements)
- {
- Selection selection = uiApp.GetSelection();
- if (selection == null) return;
- List<ElementId> idList = new List<ElementId>();
- elements.ForEach(p => idList.Add(p.Id));
- selection.SetElementIds(idList);
- }
- public static void SetShowElements(this UIApplication uiApp, List<Element> elements)
- {
- if (elements == null|| elements.Count==0)
- return;
- ElementSet set = new ElementSet();
- elements.ForEach(e => set.Insert(e));
- uiApp.ActiveUIDocument.ShowElements(set);
- uiApp.SelectElements(elements);
- }
- }
- }
|