RevitVisionUtil.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* ==============================================================================
  2. * 功能描述:RevitVisionUtil
  3. * 创 建 者:Garrett
  4. * 创建日期:2019/6/28 9:25:34
  5. * ==============================================================================*/
  6. using System.IO;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. namespace SAGA.DotNetUtils.Revit
  10. {
  11. /// <summary>
  12. /// RevitVisionUtil
  13. /// </summary>
  14. public class RevitVisionUtil
  15. {
  16. /// <summary>
  17. /// 获取Revit文件的版本
  18. /// </summary>
  19. /// <param name="path">文件路径</param>
  20. /// <returns></returns>
  21. public static string GetRevitVision(string path)
  22. {
  23. string revitVision = null;
  24. FileStream stream = new FileStream(path, FileMode.Open);
  25. int size = 1024 * 1024;
  26. byte[] bytes = new byte[size];
  27. while (stream.Read(bytes, 0, size) > 0)
  28. {
  29. string str = Encoding.Unicode.GetString(bytes);
  30. //if (str.Contains("2014"))
  31. //{
  32. // revitVision = "2014";
  33. // File.WriteAllText(@"D:\abc.txt", str);
  34. // System.Diagnostics.Process.Start("notepad.exe", path);
  35. // break;
  36. //}
  37. string pattern = @"Autodesk Revit \d{4}";
  38. var match = Regex.Match(str, pattern);
  39. if (match.Success)
  40. {
  41. revitVision = match.Value.Substring(match.Length - 4, 4);
  42. //File.WriteAllText(@"D:\abc.txt", str);
  43. break;
  44. }
  45. }
  46. return revitVision;
  47. }
  48. }
  49. }