ExportDataBuilder.cs 3.2 KB

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