You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unless I'm mistaken, it doesn't seem possible to obtain the version of a DXF file opened with GDAL. In my Python context, there's no function like GetVersion or GetVariables("ACADVER") available to retrieve the file version name.
I believe this variable is indeed read because it's among the first in the HEADER. However, it's not exposed.
In pure python, one could get this information with this dirty script:
# Mapping of AutoCAD versions to version names# from https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-A85E8E67-27CD-4C59-BE61-4DC9FADBE74Aautocad_versions= {
"AC1006": "R10",
#"AC1009": "R11 and R12","AC1009": "R12",
"AC1012": "R13",
"AC1014": "R14",
"AC1015": "AutoCAD 2000",
"AC1018": "AutoCAD 2004",
"AC1021": "AutoCAD 2007",
"AC1024": "AutoCAD 2010",
"AC1027": "AutoCAD 2013",
"AC1032": "AutoCAD 2018"
}
defget_acadver_from_dxf(dxf_file):
try:
# Open the DXF filewithopen(dxf_file, 'r') asf:
lines=f.readlines()
# Search for the line with "$ACADVER"# $ACADVER is in the header section# Tipically a DXF file, will have this part:# $ACADVER# 1# ACXXX# Where $ACADVER is the variable# 1, the group code# and ACXXX the version idfori, lineinenumerate(lines):
ifline.strip() =='$ACADVER':
# Check if the next line existsifi+2<len(lines):
# Extract the version information from the next lineacadver=lines[i+2].strip()
returnacadverelse:
raiseValueError("Version information not found after '$ACADVER' line.")
# If '$ACADVER' line not found, raise an errorraiseValueError("'$ACADVER' line not found in the DXF file.")
exceptExceptionase:
print("Error:", e)
returnNone# Example usagedxf_file="/path/to/you/autocad.dxf"acadver=get_acadver_from_dxf(dxf_file)
ifacadver:
acadvername=autocad_versions.get(acadver, "Unknown")
print("ACADVER:", acadver)
print("ACADVER Name:", acadvername)
else:
print("ACADVER not found or invalid in the DXF file.")
Would it be possible to have a method to retrieve the version of the DXF file?
Would it be possible to have a method to retrieve the version of the DXF file?
if you want to tackle this, the way to go would probably to expose that information in a dedicated "DXF" metadata domain, and you would fech it with dataset.GetMetadataItem("$ACADVER", "DXF"). (As the GDAL API is potentially usable for all drivers, we can't extend it just for the needs of a single driver)
Feature description
Unless I'm mistaken, it doesn't seem possible to obtain the version of a DXF file opened with GDAL. In my Python context, there's no function like
GetVersion
orGetVariables("ACADVER")
available to retrieve the file version name.I believe this variable is indeed read because it's among the first in the HEADER. However, it's not exposed.
In pure python, one could get this information with this dirty script:
Would it be possible to have a method to retrieve the version of the DXF file?
Thanks,
Additional context
Related issue: Guts/DicoGIS#228
The text was updated successfully, but these errors were encountered: