Beispiel #1
0
        /// <summary>
        /// Gets a <see cref="RevitFileInfo" /> instance from the given file path.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="readProperties">if set to <c>true</c> [read properties].</param>
        /// <param name="readTypes">if set to <c>true</c> [read types].</param>
        /// <returns></returns>
        /// <exception cref="T:System.ArgumentException">filePath is invalid.</exception>
        public static RevitFileInfo GetFromFile(string filePath)
        {
            if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath))
            {
                throw new ArgumentException("Please supply a valid path to a Revit document", nameof(filePath));
            }

            var rfi = new RevitFileInfo
            {
                FilePath = filePath
            };

            // Read basic file info from metadata
            try
            {
                var basicInfo  = OleDataReader.GetRawBytes(filePath, RevitFileMap.OleStreams.BASIC_FILE_INFO);
                var properties = GetProperties(basicInfo);
                rfi.ParseDocumentInfo(properties);
                rfi.ParseLocale(properties);
                rfi.ParseRevit(properties);
                rfi.ParseUsername(properties);
            }
            catch (Exception)
            {
                // TODO log the error
            }

            // Read family types from part atom
            try
            {
                rfi.PartAtom = PartAtom.GetFromFile(filePath);
                if (rfi.Format <= 0)
                {
                    rfi.Format = rfi.PartAtom?.Link?.Files?.FirstOrDefault()?.ProductVersion ?? -1;
                }
            }
            catch (Exception)
            {
                // TODO log the error
            }

            return(rfi);
        }
Beispiel #2
0
        public static int GetFormatFromFile(string filePath)
        {
            if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath))
            {
                throw new ArgumentException("Please supply a valid path to a Revit document", nameof(filePath));
            }

            try
            {
                var basicInfo           = OleDataReader.GetRawBytes(filePath, RevitFileMap.OleStreams.BASIC_FILE_INFO);
                var properties          = GetProperties(basicInfo);
                var formatFromBasicInfo = properties.GetFormat();
                if (formatFromBasicInfo > 0)
                {
                    return(formatFromBasicInfo);
                }
            }
            catch
            {
                // TODO ad logging
                // Trying to read
            }

            try
            {
                var partAtom           = PartAtom.GetFromFile(filePath);
                var formatFromPartAtom = partAtom?.Link?.Files?.FirstOrDefault()?.ProductVersion;
                if (formatFromPartAtom != null)
                {
                    return(formatFromPartAtom.GetValueOrDefault());
                }
            }
            catch (Exception ex)
            {
                throw new InvalidDataException($"Couldn't read format information from the followin file: '{filePath}'", ex);
            }

            return(-1);
        }
Beispiel #3
0
        /// <summary>
        /// Gets a <see cref="RevitFileInfo" /> instance from the given file path.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="readProperties">if set to <c>true</c> [read properties].</param>
        /// <param name="readTypes">if set to <c>true</c> [read types].</param>
        /// <returns></returns>
        /// <exception cref="T:System.ArgumentException">filePath is invalid</exception>
        public static RevitFileInfo GetFromFile(string filePath)
        {
            if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath))
            {
                throw new ArgumentException("Please supply a valid path to a Revit document", nameof(filePath));
            }

            var rfi = new RevitFileInfo
            {
                FilePath = filePath
            };

            // Read basic file info from metadata
            try
            {
                var properties = GetProperties(filePath);
                rfi.ParseDocumentInfo(properties);
                rfi.ParseLocale(properties);
                rfi.ParseRevit(properties);
                rfi.ParseUsername(properties);
            }
            catch (Exception)
            {
                // TODO log the error
            }

            // Read family types from part atom
            try
            {
                rfi.PartAtom = PartAtom.GetFromFile(filePath);
            }
            catch (Exception)
            {
                // TODO log the error
            }

            return(rfi);
        }