/*------------------------------------------------------------------------- * 功能描述: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 elements) { if (elements == null || elements.Count == 0) return; Selection selection = uiApp.GetSelection(); if (selection == null) return; List 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()); } public static void SelectElements(this UIApplication uiApp, List elements) { Selection selection = uiApp.GetSelection(); if (selection == null) return; List idList = new List(); elements.ForEach(p => idList.Add(p.Id)); selection.SetElementIds(idList); } public static void SetShowElements(this UIApplication uiApp, List 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); } } }