Drawing Version

Function Syntax (LM:dwgversion <fn>)
Current Version 1.0
Donate
Arguments
Symbol Type Description
fn String Filename of dwg / dws / dwt / dxf file
Returns
Type Description
String A string describing the drawing version of the supplied drawing file, else nil.

Function Description

This function will return a string describing the drawing version of a supplied drawing file, if possible.

The function is compatible with drawing files in dwg / dws / dwt / dxf format.

If supplied with a drawing filename without a filepath, this function will search the working directory and all AutoCAD Support File Search Paths for the supplied drawing filename, and will attempt to return the drawing version of the first matching file found.

If the supplied drawing file could not be found, or the drawing version could not be determined, this function will return nil.

Select all
;; Drawing Version  -  Lee Mac
;; Returns the version of the supplied filename (dwg/dws/dwt/dxf)

(defun LM:dwgversion ( fn / fd vr )
    (cond
        (   (null
                (and
                    (setq fn (findfile fn))
                    (setq fd (open fn "r"))
                )
            )
        )
        (   (wcmatch (strcase fn t) "*`.dw[gst]")
            (setq vr (strcase (substr (read-line fd) 1 6)))
        )
        (   (wcmatch (strcase fn t) "*`.dxf")
            (repeat 7 (read-line fd))
            (setq vr (strcase (read-line fd)))
        )
    )
    (if (= 'file (type fd)) (close fd))
    (cdr
        (assoc vr
           '(
                ("AC1027" . "2013-2015")
                ("AC1024" . "2010-2012")
                ("AC1021" . "2007-2009")
                ("AC1018" . "2004-2006")
                ("AC1015" . "2000-2002")
                ("AC1014" . "Release 14")
                ("AC1012" . "Release 13")
                ("AC1009" . "Release 11/12")
                ("AC1006" . "Release 10")
                ("AC1004" . "Release 9")
                ("AC1003" . "Release 2.60")
                ("AC1002" . "Release 2.50")
                ("AC1001" . "Release 2.22")
                ("AC2.22" . "Release 2.22")
                ("AC2.21" . "Release 2.21")
                ("AC2.10" . "Release 2.10")
                ("AC1.50" . "Release 2.05")
                ("AC1.40" . "Release 1.40")
                ("AC1.2"  . "Release 1.2")
                ("MC0.0"  . "Release 1.0")
            )
        )
    )
)

Example Programs

The following example program will prompt the user to select a drawing file (dwg / dws / dwt / dxf) and, following a valid response, will print the drawing version of the selected file to the AutoCAD command-line, if possible.

Select all
;; Prints the version of a selected drawing file

(defun c:getversion ( / fn vr )
    (if (setq fn (getfiled "" "" "dwg;dws;dwt;dxf" 16))
        (if (setq vr (LM:dwgversion fn))
            (princ (strcat "\nThe selected file is an AutoCAD " vr " format file."))
            (princ "\nThe format of the selected file could not be determined.")
        )
    )
    (princ)
)

This second example program will print the drawing version of the active drawing file, if the file has been saved.

Select all
;; Prints the version of the active drawing file

(defun c:getcversion ( / vr )
    (if (zerop (getvar 'dwgtitled))
        (princ "\nThe current drawing is unsaved.")
        (if (setq vr (LM:dwgversion (strcat (getvar 'dwgprefix) (getvar 'dwgname))))
            (princ (strcat "\nThis is an AutoCAD " vr " format file."))
            (princ "\nThe format of this file could not be determined.")
        )
    )
    (princ)
)

textsize

increase · reset · decrease

Designed & Created by Lee Mac © 2010