RevitUtils.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. File.AppendAllText(@"D:\abc.txt",vision);
  28. File.AppendAllText(@"D:\abc.txt", "\r\n");
  29. var revitVision = $"{vision}";
  30. var products = SAGA.DotNetUtils.Revit.RevitProductUtility.GetAllInstalledRevitProducts();
  31. foreach (var product in products)
  32. {
  33. File.AppendAllText(@"D:\abc.txt", product.Item1+":"+product.Item2);
  34. File.AppendAllText(@"D:\abc.txt", "\r\n");
  35. if(product.Item1==vision)
  36. File.AppendAllText(@"D:\abc.txt", (product.Item1 == vision).ToString());
  37. }
  38. return SAGA.DotNetUtils.Revit.RevitProductUtility.GetAllInstalledRevitProducts().Where(t => t.Item1==(revitVision)).Select(t => t.Item2).ToList();
  39. #if DEBUG
  40. return RevitProductUtility.GetAllInstalledRevitProducts().Where(t => t.Name == "Revit 2017").Select(x => x.InstallLocation).ToList();
  41. #else
  42. return new List<string>(){GetRevitDllPath()};
  43. #endif
  44. }
  45. #region dll路径管理
  46. /// <summary>
  47. /// 获取RevitDll,所在目录
  48. /// </summary>
  49. /// <returns></returns>
  50. public static string GetRevitDllPath()
  51. {
  52. if (!string.IsNullOrWhiteSpace(m_RevitDllPath))
  53. {
  54. return m_RevitDllPath;
  55. }
  56. return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\\RevitDlls");
  57. }
  58. private static string m_RevitDllPath;
  59. public static void SetRevitkDllPath(string path)
  60. {
  61. m_RevitDllPath = path;
  62. }
  63. #endregion
  64. }
  65. }