duheng
2025-03-05 0f831db8df9c2e4adc7feca636967a0fb1cd5e29
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using HStation.RevitDev.RevitDataExport.Common;
using System.Collections.Generic;
using System.Linq;
 
namespace HStation.RevitDev.RevitDataExport.Utility
{
    public class UIDocumentUtils
    {
        public static void ShowLinkedElements(string ids)
        {
 
            if (string.IsNullOrEmpty(ids))
            {
                return;
            }
            var idArray = ids.Split(',');
            var idList = idArray.Select(x => new ElementId(int.Parse(x)))?.ToList();
            GlobalResource.CurrentUIDocument.Selection.SetElementIds(idList);
            GlobalResource.CurrentUIDocument.ShowElements(idList);
        }
 
        public static void ShowElement(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return;
            }
            var elemId = new ElementId(int.Parse(id));
            var elem = GlobalResource.CurrentDocument.GetElement(elemId);
            if (elem == null)
            {
                GlobalResource.RevitModels.Remove(id);
                TaskDialog.Show("错误", "无效ID,已删除!");
                GlobalResource.InstancePanel.UpdateForm();
                return;
            }
            GlobalResource.CurrentUIDocument.Selection.SetElementIds(
                new List<ElementId> { elemId });
            GlobalResource.CurrentUIDocument.ShowElements(elemId);
        }
    }
}