ExportDataBuilder.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:ExportDataBuilder
  3. * 作者:xulisong
  4. * 创建时间: 2019/6/24 9:59:47
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using Autodesk.Revit.DB;
  8. using Autodesk.Revit.DB.Mechanical;
  9. using Autodesk.Revit.DB.Plumbing;
  10. using RevitExport.Export;
  11. using RevitToJBim.Common;
  12. using SAGA.RevitUtils.Extends;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. namespace RevitToJBim
  19. {
  20. public class ExportDataBuilder
  21. {
  22. /// <summary>
  23. /// 创建数据源
  24. /// </summary>
  25. /// <returns></returns>
  26. public static List<ElementWrapper> CreateExportData(Document doc)
  27. {
  28. List<ElementWrapper> wrappers = new List<ElementWrapper>();
  29. //应对传入元素,不是document全集的情况
  30. //FilteredElementCollector collector = new FilteredElementCollector(doc, elements.Select(e => e.Id).ToList());
  31. FilteredElementCollector collector = new FilteredElementCollector(doc);
  32. wrappers.AddRange(collector.Clone().FilterElements<Wall>().Select(e => new ElementWrapper(e)));
  33. wrappers.AddRange(collector.Clone().FilterElements<CurveElement>(BuiltInCategory.OST_MEPSpaceSeparationLines).Select(e => new ElementWrapper(e)));
  34. var sourceSpaces = collector.Clone().FilterElements<SpatialElement>(BuiltInCategory.OST_MEPSpaces).OfType<Space>().ToList();
  35. //附加逻辑判断
  36. // var originSpaces = collector.Clone().GetUseSpaces();
  37. wrappers.AddRange(sourceSpaces.Select(e => new ElementWrapper(e)));
  38. wrappers.AddRange(collector.Clone().FilterElements<Pipe>().Select(e => new ElementWrapper(e)));
  39. wrappers.AddRange(collector.Clone().FilterElements<Duct>().Select(e => new ElementWrapper(e)));
  40. var familyInstances = collector.Clone().FilterElements<FamilyInstance>();
  41. foreach (FamilyInstance familyInstance in familyInstances)
  42. {
  43. var tempWrapper = ElementWrapperFactory.CreateWrapper(familyInstance);
  44. if (tempWrapper != null)
  45. {
  46. wrappers.Add(tempWrapper);
  47. }
  48. }
  49. wrappers.AddRange(collector.Clone().FilterElements<Level>().Select(e => new ElementWrapper(e)));
  50. wrappers.AddRange(collector.Clone().FilterElements<Grid>().Select(e => new ElementWrapper(e)));
  51. return wrappers;
  52. }
  53. }
  54. }