Author Topic: Detect AutoCAD version  (Read 9270 times)

0 Members and 1 Guest are viewing this topic.

Daniel J. Ellis

  • Swamp Rat
  • Posts: 811
Detect AutoCAD version
« on: January 11, 2011, 08:55:39 AM »
I've been using R2011, which has a wonderful feature as part of its hatch routine to specify the layer the hatch's going to be inserted on.

This is great, until you have a routine that sets the current to where you want the hatch to go to and freezes off the random layer you had been hatching on!

I'm the only one in the office using R2011 (everyone else uses R2010) so I need a way to detect which version of AutoCAD is being run so I can do the appropriate thing with my hatch command!

Is this something that can be done with LISP?

dJE
===
dJE

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Detect AutoCAD version
« Reply #1 on: January 11, 2011, 09:04:09 AM »
http://en.wikipedia.org/wiki/.dwg

No info on 2011 yet.

There are many ways to do it.

Drawing version
http://www.theswamp.org/index.php?topic=6774.msg333989#msg333989

ACAD version
Code: [Select]
((= (rtos(atof(getvar "ACADVER"))2 2) "15.00") 2000))
 ((= (rtos(atof(getvar "ACADVER"))2 2) "15.05") 2000i))
 ((= (rtos(atof(getvar "ACADVER"))2 2) "15.06") 2002))
 ((= (rtos(atof(getvar "ACADVER"))2 2) "16.00") 2004))
 ((= (rtos(atof(getvar "ACADVER"))2 2) "16.10") 2005))
 ((= (rtos(atof(getvar "ACADVER"))2 2) "16.20") 2006))
 ((= (rtos(atof(getvar "ACADVER"))2 2) "17.00") 2007)) ; 7 8 9
 ((= (rtos(atof(getvar "ACADVER"))2 2) "18.00") 2010))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

VVA

  • Newt
  • Posts: 166
Re: Detect AutoCAD version
« Reply #2 on: January 11, 2011, 09:15:49 AM »
Code: [Select]
(defun whatAcadVer ( / Aver)
(setq Aver (atof (substr (getvar "ACADVER") 1 4)))
(cond
((= Aver 18.0) 2010) 
((= Aver 17.2) 2009)
((= Aver 17.1) 2008)
((= Aver 17.0) 2007)
((= Aver 16.2) 2006)   
((= Aver 16.1) 2005)
((= Aver 16.0) 2004)
((= Aver 15.06) 2002)
(t 2011)
)
)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Detect AutoCAD version
« Reply #3 on: January 11, 2011, 09:31:32 AM »
Code: [Select]
(defun Version? (/)
  (cdr (assoc (atof (substr (getvar 'ACADVER) 1 4))
              '((18.1 . 2011)
                (18.0 . 2010)
                (17.2 . 2009)
                (17.1 . 2008)
                (17.0 . 2007)
                (16.2 . 2006)
                (16.1 . 2005)
                (16.0 . 2004)
                (15.06 . 2002)
               )
       )
  )
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

yarik

  • Newt
  • Posts: 32
Re: Detect AutoCAD version
« Reply #4 on: January 11, 2011, 11:30:45 AM »
Hi, maybe this can help

Code: [Select]


(defun acadvers()
(setq acad(atof(vlax-get-property (vlax-get-acad-object) 'version)))
(if (= acad 18.1)
(setq vers "ACAD2011")
)
(if (= acad 18.0)
(setq vers "ACAD2010")
)
vers
)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Detect AutoCAD version
« Reply #5 on: January 11, 2011, 12:55:20 PM »
Another approach ... although I'm sure it can be broken  :-D

Code: [Select]
(defun getacadversion (/ path)
  (if (setq path (findfile "acad.exe"))
    (apply
      'strcat
      (mapcar 'chr (vl-remove-if-not '(lambda (x) (and (> x 47) (< x 58))) (vl-string->list path)))
    )
  )
)
(getacadversion)

;;Returns "2009"

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Detect AutoCAD version
« Reply #6 on: January 11, 2011, 01:20:50 PM »
Another approach ... although I'm sure it can be broken  :-D

Code: [Select]
(defun getacadversion (/ path)
  (if (setq path (findfile "acad.exe"))
    (apply
      'strcat
      (mapcar 'chr (vl-remove-if-not '(lambda (x) (and (> x 47) (< x 58))) (vl-string->list path)))
    )
  )
)
(getacadversion)

;;Returns "2009"
Code: [Select]
Command: (findfile "acad.exe")
"C:\\Program Files\\Autodesk\\AutoCAD Civil 3D 2011\\acad.exe"
Returns: "32011"

Very cool idea. Way to think outside the box.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Detect AutoCAD version
« Reply #7 on: January 11, 2011, 03:15:36 PM »
Another approach ... although I'm sure it can be broken  :-D

Code: [Select]
(defun getacadversion (/ path)
  (if (setq path (findfile "acad.exe"))
    (apply
      'strcat
      (mapcar 'chr (vl-remove-if-not '(lambda (x) (and (> x 47) (< x 58))) (vl-string->list path)))
    )
  )
)
(getacadversion)

;;Returns "2009"
Code: [Select]
Command: (findfile "acad.exe")
"C:\\Program Files\\Autodesk\\AutoCAD Civil 3D 2011\\acad.exe"
Returns: "32011"

Very cool idea. Way to think outside the box.

:) Thanks Alan ... perhaps this will fix it:


Code: [Select]
(defun getacadversion (/ path)
  (and (setq path (findfile "acad.exe"))
       (setq path (vl-remove-if-not '(lambda (x) (and (> x 47) (< x 58))) (vl-string->list path)))
       (setq path (apply 'strcat (mapcar 'chr path)))
       (setq path (substr path (- (1+ (strlen path)) 4)))
  )
  path
)
(getacadversion)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Detect AutoCAD version
« Reply #8 on: January 11, 2011, 03:34:41 PM »
Another approach ... although I'm sure it can be broken  :-D

Code: [Select]
(defun getacadversion (/ path)
  (if (setq path (findfile "acad.exe"))
    (apply
      'strcat
      (mapcar 'chr (vl-remove-if-not '(lambda (x) (and (> x 47) (< x 58))) (vl-string->list path)))
    )
  )
)
(getacadversion)

;;Returns "2009"
Code: [Select]
Command: (findfile "acad.exe")
"C:\\Program Files\\Autodesk\\AutoCAD Civil 3D 2011\\acad.exe"
Returns: "32011"

Very cool idea. Way to think outside the box.

:) Thanks Alan ... perhaps this will fix it:


Code: [Select]
(defun getacadversion (/ path)
  (and (setq path (findfile "acad.exe"))
       (setq path (vl-remove-if-not '(lambda (x) (and (> x 47) (< x 58))) (vl-string->list path)))
       (setq path (apply 'strcat (mapcar 'chr path)))
       (setq path (substr path (- (1+ (strlen path)) 4)))
  )
  path
)
(getacadversion)


Slight variant...
Code: [Select]
(defun getacadversion (/ path)
  (if (setq path (findfile "acad.exe"))
    ((lambda (str) (substr str (- (1+ (strlen str)) 4)))
      (vl-list->string
        (vl-remove-if-not (function (lambda (x) (and (> x 47) (< x 58)))) (vl-string->list path))
      )
    )
  )
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Chris

  • Swamp Rat
  • Posts: 548
Re: Detect AutoCAD version
« Reply #9 on: January 11, 2011, 03:34:55 PM »
personally I prefer this:
Code: [Select]
(atoi (vl-string-right-trim " (en)" (vl-string-left-trim "Visual LISP " (ver))))
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Detect AutoCAD version
« Reply #10 on: January 11, 2011, 03:41:52 PM »
personally I prefer this:
Code: [Select]
(atoi (vl-string-right-trim " (en)" (vl-string-left-trim "Visual LISP " (ver))))
Code: [Select]
(defun getacadversion (/)
  (vl-list->string
    (vl-remove-if-not (function (lambda (x) (and (> x 47) (< x 58)))) (vl-string->list (ver)))
  )
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
Re: Detect AutoCAD version
« Reply #11 on: January 11, 2011, 03:44:52 PM »
 :ugly:

Code: [Select]
(defun version nil
  (cdr
    (assoc
      (atof
        (
          (lambda ( key )
            (substr
              (setq key
                (substr key 1
                  (vl-string-position 92 key nil t)
                )
              )
              (+ 3 (vl-string-position 92 key nil t))
            )
          )
          (vlax-product-key)
        )
      )
     '(
        (18.1  . 2011)
        (18.0  . 2010)
        (17.2  . 2009)
        (17.1  . 2008)
        (17.0  . 2007)
        (16.2  . 2006)
        (16.1  . 2005)
        (16.0  . 2004)
        (15.06 . 2002)
      )
    )
  )
)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Detect AutoCAD version
« Reply #12 on: January 11, 2011, 03:47:14 PM »
:ugly:

Code: [Select]
(defun version nil
  (cdr
    (assoc
      (atof
        (
          (lambda ( key )
            (substr
              (setq key
                (substr key 1
                  (vl-string-position 92 key nil t)
                )
              )
              (+ 3 (vl-string-position 92 key nil t))
            )
          )
          (vlax-product-key)
        )
      )
     '(
        (18.1  . 2011)
        (18.0  . 2010)
        (17.2  . 2009)
        (17.1  . 2008)
        (17.0  . 2007)
        (16.2  . 2006)
        (16.1  . 2005)
        (16.0  . 2004)
        (15.06 . 2002)
      )
    )
  )
)

LoL, I think I'll stick with (getvar 'ACADVER).  :lol: Nice work either way.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
Re: Detect AutoCAD version
« Reply #13 on: January 11, 2011, 03:54:44 PM »
LoL, I think I'll stick with (getvar 'ACADVER).

 :-D  Me too  :-)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Detect AutoCAD version
« Reply #14 on: January 11, 2011, 04:07:19 PM »
my version
Code: [Select]
(atoi (substr (ver) 13))

Daniel J. Ellis

  • Swamp Rat
  • Posts: 811
Re: Detect AutoCAD version
« Reply #15 on: January 11, 2011, 04:24:52 PM »
Thanks CAB, et al, it's the ACAD version I need, so RTOS (ACADVER) is the way to go.

I'll probably read the wikilink just to be geeky, though ^_^

Ronjonp, If I read your method right it searches for the acad.exe file and extrapolates the version from the path?  Could this differential between two different versions on the same computer (I have both R2011 and R2010 installed)?


dJE

http://en.wikipedia.org/wiki/.dwg

No info on 2011 yet.

There are many ways to do it.

Drawing version
http://www.theswamp.org/index.php?topic=6774.msg333989#msg333989

ACAD version
Code: [Select]
((= (rtos(atof(getvar "ACADVER"))2 2) "15.00") 2000))
 ((= (rtos(atof(getvar "ACADVER"))2 2) "15.05") 2000i))
 ((= (rtos(atof(getvar "ACADVER"))2 2) "15.06") 2002))
 ((= (rtos(atof(getvar "ACADVER"))2 2) "16.00") 2004))
 ((= (rtos(atof(getvar "ACADVER"))2 2) "16.10") 2005))
 ((= (rtos(atof(getvar "ACADVER"))2 2) "16.20") 2006))
 ((= (rtos(atof(getvar "ACADVER"))2 2) "17.00") 2007)) ; 7 8 9
 ((= (rtos(atof(getvar "ACADVER"))2 2) "18.00") 2010))
===
dJE

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
Re: Detect AutoCAD version
« Reply #16 on: January 11, 2011, 04:26:27 PM »
my version
Code: [Select]
(atoi (substr (ver) 13))

Bravo  8-)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Detect AutoCAD version
« Reply #17 on: January 11, 2011, 04:27:15 PM »
Thanks CAB, et al, it's the ACAD version I need, so RTOS (ACADVER) is the way to go.

I'll probably read the wikilink just to be geeky, though ^_^

Ronjonp, If I read your method right it searches for the acad.exe file and extrapolates the version from the path?  Could this differential between two different versions on the same computer (I have both R2011 and R2010 installed)?


dJE

http://en.wikipedia.org/wiki/.dwg

No info on 2011 yet.

There are many ways to do it.

Drawing version
http://www.theswamp.org/index.php?topic=6774.msg333989#msg333989

ACAD version
Code: [Select]
((= (rtos(atof(getvar "ACADVER"))2 2) "15.00") 2000))
 ((= (rtos(atof(getvar "ACADVER"))2 2) "15.05") 2000i))
 ((= (rtos(atof(getvar "ACADVER"))2 2) "15.06") 2002))
 ((= (rtos(atof(getvar "ACADVER"))2 2) "16.00") 2004))
 ((= (rtos(atof(getvar "ACADVER"))2 2) "16.10") 2005))
 ((= (rtos(atof(getvar "ACADVER"))2 2) "16.20") 2006))
 ((= (rtos(atof(getvar "ACADVER"))2 2) "17.00") 2007)) ; 7 8 9
 ((= (rtos(atof(getvar "ACADVER"))2 2) "18.00") 2010))
Beware of your dimzin variable being something other than zero (suppressing zeros will cause problems when comparing strings).
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Detect AutoCAD version
« Reply #18 on: January 11, 2011, 04:37:28 PM »
personally I prefer this:
Code: [Select]
(atoi (vl-string-right-trim " (en)" (vl-string-left-trim "Visual LISP " (ver))))
Code: [Select]
(defun getacadversion (/)
  (vl-list->string
    (vl-remove-if-not (function (lambda (x) (and (> x 47) (< x 58)))) (vl-string->list (ver)))
  )
)

I like that one  8-)  Forgot about (ver)  :lol:

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Detect AutoCAD version
« Reply #19 on: January 11, 2011, 04:38:33 PM »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Detect AutoCAD version
« Reply #20 on: January 11, 2011, 04:39:26 PM »
my version
Code: [Select]
(atoi (substr (ver) 13))

Bravo  8-)

X2
X3
He has a way of making us all look/feel stupid and happy, at the same time.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Detect AutoCAD version
« Reply #21 on: January 11, 2011, 04:47:37 PM »
Mood has improved! Thank you :)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Detect AutoCAD version
« Reply #22 on: January 11, 2011, 05:26:24 PM »
Quote
Thanks CAB, et al, it's the ACAD version I need, so RTOS (ACADVER) is the way to go.

I'll probably read the wikilink just to be geeky, though ^_^

Ronjonp, If I read your method right it searches for the acad.exe file and extrapolates the version from the path?  Could this differential between two different versions on the same computer (I have both R2011 and R2010 installed)?

...

Whichever AutoCAD version the code is run in should match... unless for some reason the other acad path is in the search paths as well.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

did.ave

  • Guest
Re: Detect AutoCAD version
« Reply #23 on: January 12, 2011, 04:53:41 AM »
coucou

Evgeniy is always the most concise

i'm french, so I say merci

amicalement

Chris

  • Swamp Rat
  • Posts: 548
Re: Detect AutoCAD version
« Reply #24 on: January 12, 2011, 08:46:27 AM »
my version
Code: [Select]
(atoi (substr (ver) 13))

Bravo  8-)

X2
X3
He has a way of making us all look/feel stupid and happy, at the same time.
X4 - I'm changing my code.
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Detect AutoCAD version
« Reply #25 on: January 12, 2011, 06:19:44 PM »