zhangyuekai
2024-07-01 0e3464b6adf776686e66bb3189441ab1a65a088e
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
45
46
47
48
49
50
51
52
53
using Autodesk.Revit.DB;
using HStation.RevitDev.RevitDataExport.Utility;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
 
namespace HStation.RevitDev.RevitDataExport.Service
{
    public class RevitMepCategoryService
    {
        public static Dictionary<string, List<Element>> GroupElements(IEnumerable<Element> systemElems)
        {
            var result = new Dictionary<string, List<Element>>();
            var parsers = ParserManager.Instance.Parsers;
            foreach (Element elem in systemElems)
            {
                bool pass = false;
                foreach (var parser in parsers)
                {
                    if (parser.IsPass(elem))
                    {
                        pass = true;
                        var key = parser.GetParserName();
                        if (!result.ContainsKey(key))
                        {
                            result.Add(key, new List<Element>());
                        }
                        if (!result[key].Any(x=>x.Id.IntegerValue == elem.Id.IntegerValue))
                        {
                            result[key].Add(elem);
                        }
                        break;
                    }
                }
                if (!pass)
                {
                    //加入其它构件类型
                    if (!result.ContainsKey("其他"))
                    {
                        result.Add("其他", new List<Element>());
                    }
                    result["其他"].Add(elem);
                }
            }
            return result;
        }
    }
}