VersionManager.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:VersionManager
  3. * 作者:xulisong
  4. * 创建时间: 2019/1/16 15:47:21
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using Autodesk.RevitAddIns;
  13. namespace RevitVersion
  14. {
  15. /// <summary>
  16. /// 版本管理
  17. /// </summary>
  18. public class VersionManager
  19. {
  20. static VersionManager()
  21. {
  22. Current = new VersionManager();
  23. }
  24. public static VersionManager Current
  25. {
  26. get;private set;
  27. }
  28. /// <summary>
  29. /// 当前版本信息
  30. /// </summary>
  31. public Version Version
  32. {
  33. get
  34. {
  35. #if R14
  36. return Version.Revit2017;
  37. #elif R15
  38. return Version.Revit2015;
  39. #elif R16
  40. return Version.Revit2016;
  41. #elif R17
  42. return Version.Revit2017;
  43. #elif R18
  44. return Version.Revit2018;
  45. #endif
  46. }
  47. }
  48. public static List<RevitProduct> GetRevitProducts()
  49. {
  50. return RevitProductUtility.GetAllInstalledRevitProducts();
  51. }
  52. private RevitProduct m_Product;
  53. public RevitProduct Product
  54. {
  55. get
  56. {
  57. if (m_Product == null)
  58. {
  59. var products = GetRevitProducts();
  60. m_Product = products.FirstOrDefault(p => p.Version.ToString() == Version.ToString());
  61. }
  62. return m_Product;
  63. }
  64. }
  65. }
  66. }