ExportDataBuilder.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. using RevitToJBim.Extension;
  19. namespace RevitToJBim
  20. {
  21. public class ExportDataBuilder
  22. {
  23. /// <summary>
  24. /// 创建数据源
  25. /// </summary>
  26. /// <returns></returns>
  27. public static List<ElementWrapper> CreateExportData(Document doc)
  28. {
  29. List<ElementWrapper> wrappers = new List<ElementWrapper>();
  30. //应对传入元素,不是document全集的情况
  31. //FilteredElementCollector collector = new FilteredElementCollector(doc, elements.Select(e => e.Id).ToList());
  32. #region Unit
  33. var formatOptions = doc.GetUnits().GetFormatOptions(UnitType.UT_Length);
  34. ElementWrapper wrapper = new ElementWrapper(formatOptions, null);
  35. wrappers.Add(wrapper);
  36. #endregion
  37. FilteredElementCollector collector = new FilteredElementCollector(doc);
  38. wrappers.AddRange(collector.Clone().FilterElements<Wall>().Select(e => new ElementWrapper(e)));
  39. wrappers.AddRange(collector.Clone().FilterElements<CurveElement>(BuiltInCategory.OST_MEPSpaceSeparationLines).Select(e => new ElementWrapper(e)));
  40. var sourceSpaces = collector.Clone().FilterElements<SpatialElement>(BuiltInCategory.OST_MEPSpaces).OfType<Space>().Where(t=>t.IsSpace()).ToList();
  41. wrappers.AddRange(sourceSpaces.Select(e => new ElementWrapper(e)));
  42. wrappers.AddRange(collector.Clone().FilterElements<Pipe>().Select(e => new ElementWrapper(e)));
  43. wrappers.AddRange(collector.Clone().FilterElements<Duct>().Select(e => new ElementWrapper(e)));
  44. var familyInstances = collector.Clone().FilterElements<FamilyInstance>();
  45. foreach (FamilyInstance familyInstance in familyInstances)
  46. {
  47. var tempWrapper = ElementWrapperFactory.CreateWrapper(familyInstance);
  48. if (tempWrapper != null)
  49. {
  50. wrappers.Add(tempWrapper);
  51. }
  52. }
  53. wrappers.AddRange(collector.Clone().FilterElements<Level>().Select(e => new ElementWrapper(e)));
  54. wrappers.AddRange(collector.Clone().FilterElements<Grid>().Select(e => new ElementWrapper(e)));
  55. return wrappers;
  56. }
  57. }
  58. }