MCPcopy Create free account
hub / github.com/CodeCavePro/revitless-toolkit / GetFromFile

Method GetFromFile

src/OLE/RevitFileInfo.cs:125–164  ·  view source on GitHub ↗

Gets a instance from the given file path. The file path. filePath is invalid.

(string filePath)

Source from the content-addressed store, hash-verified

123 /// <returns></returns>
124 /// <exception cref="T:System.ArgumentException">filePath is invalid.</exception>
125 public static RevitFileInfo GetFromFile(string filePath)
126 {
127 if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath))
128 throw new ArgumentException("Please supply a valid path to a Revit document", nameof(filePath));
129
130 var rfi = new RevitFileInfo
131 {
132 FilePath = filePath
133 };
134
135 // Read basic file info from metadata
136 try
137 {
138 var basicInfo = OleDataReader.GetRawBytes(filePath, RevitFileMap.OleStreams.BASIC_FILE_INFO);
139 var properties = GetProperties(basicInfo);
140 rfi.ParseDocumentInfo(properties);
141 rfi.ParseLocale(properties);
142 rfi.ParseRevit(properties);
143 rfi.ParseUsername(properties);
144 }
145 catch (Exception ex)
146 {
147 // TODO log the error
148 Console.WriteLine($"Failed to get {nameof(RevitFileInfo)} from the following file '{filePath}': {ex}");
149 }
150
151 // Read family types from part atom
152 try
153 {
154 rfi.PartAtom = PartAtom.GetFromFile(filePath);
155 if (rfi.Format <= 0)
156 rfi.Format = rfi.PartAtom?.Link?.Files?.FirstOrDefault()?.ProductVersion ?? -1;
157 }
158 catch (Exception)
159 {
160 // TODO log the error
161 }
162
163 return rfi;
164 }
165
166 #endregion
167

Callers 1

GetFormatFromFileMethod · 0.45

Calls 5

GetRawBytesMethod · 0.80
ParseDocumentInfoMethod · 0.80
ParseLocaleMethod · 0.80
ParseRevitMethod · 0.80
ParseUsernameMethod · 0.80

Tested by

no test coverage detected