zoukankan      html  css  js  c++  java
  • Revit二次开发,获取模型版本信息

    string path = @"C:xxx.rfa";//模型地址
    BasicFileInfo fileInfo
    =BasicFileInfo.Extract(path);//引入Autodesk.Revit.DB.BasicFileInfo
    MessageBox.Show(fileInfo.SavedInVersion); 

     该方法在Revit 2020下已失效。

    以下这是在谷歌找到的模型版本信息获取方式,理论山兼容所有版本,亲测可用

      private string ReadFileVersion(string filePath)
            {
                string fileVersion = null;
                var rawData = GetRawBasicFileInfo(filePath);
                var rawString = System.Text.Encoding.Unicode.GetString(rawData);
                var fileInfoData = rawString.Split(new string[] { "", "
    " }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var item in fileInfoData)
                {
                    if (item.StartsWith("Revit Build"))
                    {
                        int colonIndex = item.IndexOf("k");
                        if (colonIndex > -1)
                        {
                            fileVersion = item.Substring(colonIndex + 1);
                            int bracketsIndex = fileVersion.IndexOf("(");
                            fileVersion = fileVersion.Substring(0, bracketsIndex);
                        }
                    }   
                }
                return fileVersion;
            }
            private const string StreamName = "BasicFileInfo";
            private static byte[] GetRawBasicFileInfo(string revitFileName)
            {
                if (!StructuredStorageUtils.IsFileStucturedStorage(
                  revitFileName))
                {
                    throw new NotSupportedException(
                      "File is not a structured storage file");
                }
    
                using (StructuredStorageRoot ssRoot =
                    new StructuredStorageRoot(revitFileName))
                {
                    if (!ssRoot.BaseRoot.StreamExists(StreamName))
                        throw new NotSupportedException(string.Format(
                          "File doesn't contain {0} stream", StreamName));
    
                    StreamInfo imageStreamInfo =
                        ssRoot.BaseRoot.GetStreamInfo(StreamName);
    
                    using (Stream stream = imageStreamInfo.GetStream(
                      FileMode.Open, FileAccess.Read))
                    {
                        byte[] buffer = new byte[stream.Length];
                        stream.Read(buffer, 0, buffer.Length);
                        return buffer;
                    }
                }
            }
            public static class StructuredStorageUtils
            {
                [DllImport("ole32.dll")]
                static extern int StgIsStorageFile(
                [MarshalAs( UnmanagedType.LPWStr )]string pwcsName);
    
                public static bool IsFileStucturedStorage(
                  string fileName)
                {
                    int res = StgIsStorageFile(fileName);
    
                    if (res == 0)
                        return true;
    
                    if (res == 1)
                        return false;
    
                    throw new FileNotFoundException(
                      "File not found", fileName);
                }
            }

    转自此篇播客:https://thebuildingcoder.typepad.com/blog/2013/01/basic-file-info-and-rvt-file-version.html
  • 相关阅读:
    算法导论读书笔记(未完成)
    工作心理学(未完成)
    面试疑难点解析
    aop难点解析。
    Mybatis框架解析之Builder解析
    HashMap原理总结
    编程基础的重要性(程序员之路)
    Java HashMap详解
    Java源码分析系列之HttpServletRequest源码分析
    JFinal源码 分析之 Core包分析
  • 原文地址:https://www.cnblogs.com/wenqiang1266/p/7030263.html
Copyright © 2011-2022 走看看