RevitUtils.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:RevitUtils
  3. * 作者:xulisong
  4. * 创建时间: 2019/7/29 9:08:18
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using Autodesk.RevitAddIns;
  14. using SAGA.DotNetUtils;
  15. namespace ExportStart
  16. {
  17. public class RevitUtils
  18. {
  19. /// <summary>
  20. /// 获取Revit搜索dll路径
  21. /// </summary>
  22. /// <returns></returns>
  23. public static List<string> GetSearchPath()
  24. {
  25. //选择版本时,预先将版本信息写在RevitFileVision.txt文件中,读取版本号
  26. var vision = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, StarterConst.RevitFileVisionFile));
  27. var revitVision = $"{vision}";
  28. return SAGA.DotNetUtils.Revit.RevitProductUtility.GetAllInstalledRevitProducts().Where(t => t.Item1==(revitVision)).Select(t => t.Item2).ToList();
  29. #if DEBUG
  30. return RevitProductUtility.GetAllInstalledRevitProducts().Where(t => t.Name == "Revit 2017").Select(x => x.InstallLocation).ToList();
  31. #else
  32. return new List<string>(){GetRevitDllPath()};
  33. #endif
  34. }
  35. #region dll路径管理
  36. /// <summary>
  37. /// 获取RevitDll,所在目录
  38. /// </summary>
  39. /// <returns></returns>
  40. public static string GetRevitDllPath()
  41. {
  42. if (!string.IsNullOrWhiteSpace(m_RevitDllPath))
  43. {
  44. return m_RevitDllPath;
  45. }
  46. return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\\RevitDlls");
  47. }
  48. private static string m_RevitDllPath;
  49. public static void SetRevitkDllPath(string path)
  50. {
  51. m_RevitDllPath = path;
  52. }
  53. #endregion
  54. }
  55. }