RevitVisionUtil.cs 1.8 KB

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