Converter.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. var result = new XYZ()
  42. {
  43. X = FtToUse(xyz.X),
  44. Y = FtToUse(xyz.Y)
  45. };
  46. if (!ignoreZ)
  47. {
  48. result.Z = FtToUse(xyz.Z);
  49. }
  50. return result;
  51. }
  52. /// <summary>
  53. /// 转换成向量
  54. /// </summary>
  55. /// <param name="xyz"></param>
  56. /// <returns></returns>
  57. public static XYZ ConvertToDirection(Autodesk.Revit.DB.XYZ xyz)
  58. {
  59. return new XYZ() { X = xyz.X, Y = xyz.Y, Z = xyz.Z, };
  60. }
  61. /// <summary>
  62. /// 将点转换成毫米单位形式
  63. /// </summary>
  64. /// <param name="xyzs"></param>
  65. /// <param name="ignoreZ">转换是否忽略Z</param>
  66. /// <returns></returns>
  67. public static List<XYZ> ConvertToXYZs(List<Autodesk.Revit.DB.XYZ> xyzs, bool ignoreZ=false)
  68. {
  69. return xyzs.Select(xyz=>ConvertToXYZ(xyz, ignoreZ)).ToList();
  70. }
  71. }
  72. }