Created
January 14, 2018 04:25
-
-
Save joakimsk/ad19c8ace8f22a68c8922ec4c8d4bdbc to your computer and use it in GitHub Desktop.
Autocad DWG version read using python3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# http://vislab-ccom.unh.edu/~schwehr/rt/python-binary-files.html | |
# https://knowledge.autodesk.com/support/autocad/learn-explore/caas/sfdcarticles/sfdcarticles/drawing-version-codes-for-autocad.html | |
# MC0.0 - DWG Release 1.1 | |
# AC1.2 - DWG Release 1.2 | |
# AC1.4 - DWG Release 1.4 | |
# AC1.50 - DWG Release 2.0 | |
# AC2.10 - DWG Release 2.10 | |
# AC1002 - DWG Release 2.5 | |
# AC1003 - DWG Release 2.6 | |
# AC1004 - DWG Release 9 | |
# AC1006 - DWG Release 10 | |
# AC1009 - DWG Release 11/12 (LT R1/R2) | |
# AC1012 - DWG Release 13 (LT95) | |
# AC1014 - DWG Release 14, 14.01 (LT97/LT98) | |
# AC1015 - DWG AutoCAD 2000/2000i/2002 | |
# AC1018 - DWG AutoCAD 2004/2005/2006 | |
# AC1021 - DWG AutoCAD 2007/2008/2009 | |
# AC1024 - DWG AutoCAD 2010/2011/2012 | |
# AC1027 - DWG AutoCAD 2013/2014/2015/2016/2017 | |
# AC1032 - DWG AutoCAD 2018 | |
import binascii, sys | |
def findDWGVersion(filename): | |
with open(filename, "rb") as binary_file: | |
# Read the whole file at once | |
data = binary_file.read() | |
# Seek position and read N bytes | |
binary_file.seek(0) # Go to beginning | |
couple_bytes = binary_file.read(6) | |
version_string = couple_bytes.decode('UTF-8') | |
return version_string | |
def main(argv): | |
print(findDWGVersion("file.dwg")) | |
if __name__== "__main__": | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment