Skip to content

Instantly share code, notes, and snippets.

@Cyril-Pop
Last active March 14, 2020 06:57
Show Gist options
  • Save Cyril-Pop/c07a2cd40d6c48b76e0cd017d012dd21 to your computer and use it in GitHub Desktop.
Save Cyril-Pop/c07a2cd40d6c48b76e0cd017d012dd21 to your computer and use it in GitHub Desktop.
import os
import os.path as op
import olefile
import re
def getfileInfo(bfi):
msgbox = 'Version non trouvée'
file_info_read = bfi.read()
for codec , regex in [['utf_16_le', r"(\d{4})..Build"], ['utf_16_be', r"Format.+?(\d{4})"]]:
file_info = file_info_read.decode(codec, "ignore")
if re.search(regex, file_info) is not None:
rvt_file_version = re.search(regex, file_info).group(1)
rvtversion = 'Fichier Revit version {}'.format(rvt_file_version)
break
return rvtversion, file_info
def get_rvt_file_version(rvt_file):
if op.exists(rvt_file):
if olefile.isOleFile(rvt_file):
rvt_ole = olefile.OleFileIO(rvt_file)
bfi = rvt_ole.openstream("BasicFileInfo")
rvtversion, file_info = getfileInfo(bfi)
return rvtversion
else:
rvtversion = "le fichier n'a pas de structure OLE"
return rvtversion
else:
rvtversion = "Fichier non trouvé"
return rvtversion
#usage
print(get_rvt_file_version("C:\\exemple.rvt"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment