Converter.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:Converter
  3. * 作者:xulisong
  4. * 创建时间: 2019/6/17 12:01:36
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using JBIM;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using JBIM.Definition;
  14. using SAGA.RevitUtils.Extends;
  15. namespace RevitToJBim.Common
  16. {
  17. public static class BimConvert
  18. {
  19. public static readonly int CoordinateDecimalDigits = 2;
  20. public static double Round(double coordinateDecimal)
  21. {
  22. return Math.Round(coordinateDecimal, CoordinateDecimalDigits);
  23. }
  24. /// <summary>
  25. /// 英尺转换成现在阶段使用单位
  26. /// </summary>
  27. /// <param name="footValue"></param>
  28. /// <returns></returns>
  29. public static double FtToUse(this double footValue)
  30. {
  31. return Round(footValue.FromApi());
  32. }
  33. /// <summary>
  34. /// 将点转换成毫米单位形式
  35. /// </summary>
  36. /// <param name="xyz"></param>
  37. /// <param name="ignoreZ">转换是否忽略Z</param>
  38. /// <returns></returns>
  39. public static XYZ ConvertToXYZ(Autodesk.Revit.DB.XYZ xyz,bool ignoreZ=false)
  40. {
  41. if (xyz == null) return null;
  42. var result = new XYZ()
  43. {
  44. X = FtToUse(xyz.X),
  45. Y = FtToUse(xyz.Y)
  46. };
  47. if (!ignoreZ)
  48. {
  49. result.Z = FtToUse(xyz.Z);
  50. }
  51. return result;
  52. }
  53. /// <summary>
  54. /// 转换成向量
  55. /// </summary>
  56. /// <param name="xyz"></param>
  57. /// <returns></returns>
  58. public static XYZ ConvertToDirection(Autodesk.Revit.DB.XYZ xyz)
  59. {
  60. return new XYZ() { X = xyz.X, Y = xyz.Y, Z = xyz.Z, };
  61. }
  62. /// <summary>
  63. /// 将点转换成毫米单位形式
  64. /// </summary>
  65. /// <param name="xyzs"></param>
  66. /// <param name="ignoreZ">转换是否忽略Z</param>
  67. /// <returns></returns>
  68. public static List<XYZ> ConvertToXYZs(List<Autodesk.Revit.DB.XYZ> xyzs, bool ignoreZ=false)
  69. {
  70. return xyzs.Select(xyz=>ConvertToXYZ(xyz, ignoreZ)).Where(t=>t!=null).ToList();
  71. }
  72. }
  73. }