Variable for DWG Version

Variable for DWG Version

Anonymous
Not applicable
1,387 Views
5 Replies
Message 1 of 6

Variable for DWG Version

Anonymous
Not applicable

Dear community,

 

I would like to display in the status bar the dwg version of the currently active document = "2013", "2018", etc., or in a similar form. Which variabel will allow me to get back such a value? Unfortunately, I didn't find any. I already have a suitable LISP.

 

Or do I have another way to do it?

 

Reason: We save the DWG in the currently used version (eg 2018) and also in the version for other uses (eg 2013). However, it happens that a person accidentally modifies the other version, because he accidentally opened it for any reason.

 

Thank you in advance and have a nice Easter

 

0 Likes
Accepted solutions (1)
1,388 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

It's the ACADVER System Variable.  Read Help about it to see the relationship between its number and the AutoCAD version.  You can get the number part as a number with the one decimal place, without the occasion 's' or parenthetical part, with:

 

(atof (getvar 'acadver))

 

You would probably need to make a list of pairings such as  '((24.0 "2021") (23.1 "2020") (23.0 "2019"))  [etc,] then use something like:

 

(cadr (assoc (atof (getvar 'acadver)) theList))

 

to extract the version year for inclusion in something that needs it in text-string form, or without the quotation marks if you can use the year as an integer.

Kent Cooper, AIA
Message 3 of 6

Anonymous
Not applicable

@Kent1Cooper,

 

very good, many thanks for your help.

0 Likes
Message 4 of 6

ronjonp
Mentor
Mentor

@Kent1Cooper ACADVER does not return the version of the opened drawing ( which is what I think the OP wants? ), it returns the version of AutoCAD being used.

 

I think this would be more suitable:

(defun mp-get-dwg-ver ( dwg / handle stream )
    ;; SOURCE
    ;; http://www.theswamp.org/index.php?topic=56316.msg602004#msg602004
    ;;  Return the specified drawing's version as a string representing
    ;;  the AutoCAD versions that create and support the version natively,
    ;;  e.g. "2018/2019/2020/2021". Of course drawings saved by Civil3D
    ;;  enjoy a special versioning hell that doesn't precisely follow this
    ;;  schema. Thanks Autodesk.
 
    (cond
        ((null (setq handle (open dwg "r"))) nil) ;; could not open drawing, return nil
        ((progn (setq stream (substr (read-line handle) 1 6))(close handle)))
        ((eq "AC1032" stream) "2018/2019/2020/2021")
        ((eq "AC1027" stream) "2013/2014/2015/2016/2017")
        ((eq "AC1024" stream) "2010/2011/2012")
        ((eq "AC1021" stream) "2007/2008/2009")
        ((eq "AC1018" stream) "2004/2005/2006")
        ((eq "AC1015" stream) "2000/2000I/2002") ;; was 2000i, forced uppercase
        ((eq "AC1014" stream) "R14")
        ((eq "AC1012" stream) "13")
        ((eq "AC1009" stream) "11,12")
        ((eq "AC1006" stream) "10")
        ((eq "AC1004" stream) "9")
        ((eq "AC1003" stream) "2.6")
        ((eq "AC1002" stream) "2.5")
        ((eq "AC2.10" stream) "2.10")
        ((eq "AC1.50" stream) "2.0")
        ((eq "AC1.4" (setq stream (substr stream 1 5))) "1.4")
        ((eq "AC1.2" stream) "1.2")
        ((eq "MC0.0" stream) "1.1")
        ("Doesn't appear to be an AutoCAD dwg, cue sad trombone.")
    )
)
;; Usage
(mp-get-dwg-ver (strcat (getvar 'dwgprefix)(getvar 'dwgname)))
Message 5 of 6

ronjonp
Mentor
Mentor

To see the version you have to read the header of the file ( posted an example from TheSwamp in my previous post )

ronjonp_0-1617296155588.png

 

Message 6 of 6

Sea-Haven
Mentor
Mentor

To quote someone "the first 6 bits of the DWG Header variable stands for the version string"

 

Ok now to read the 1st 6 bits via Lisp I am sure found something once.

0 Likes