TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Daniel J. Ellis on January 11, 2011, 08:55:39 AM

Title: Detect AutoCAD version
Post by: Daniel J. Ellis 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
Title: Re: Detect AutoCAD version
Post by: CAB 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))
Title: Re: Detect AutoCAD version
Post by: VVA 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)
)
)
Title: Re: Detect AutoCAD version
Post by: alanjt 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)
               )
       )
  )
)
Title: Re: Detect AutoCAD version
Post by: yarik 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
)
Title: Re: Detect AutoCAD version
Post by: ronjonp 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"
Title: Re: Detect AutoCAD version
Post by: alanjt 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.
Title: Re: Detect AutoCAD version
Post by: ronjonp 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)
Title: Re: Detect AutoCAD version
Post by: alanjt 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))
      )
    )
  )
)
Title: Re: Detect AutoCAD version
Post by: Chris 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))))
Title: Re: Detect AutoCAD version
Post by: alanjt 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)))
  )
)
Title: Re: Detect AutoCAD version
Post by: Lee Mac 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)
      )
    )
  )
)
Title: Re: Detect AutoCAD version
Post by: alanjt 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.
Title: Re: Detect AutoCAD version
Post by: Lee Mac on January 11, 2011, 03:54:44 PM
LoL, I think I'll stick with (getvar 'ACADVER).

 :-D  Me too  :-)
Title: Re: Detect AutoCAD version
Post by: ElpanovEvgeniy on January 11, 2011, 04:07:19 PM
my version
Code: [Select]
(atoi (substr (ver) 13))
Title: Re: Detect AutoCAD version
Post by: Daniel J. Ellis 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))
Title: Re: Detect AutoCAD version
Post by: Lee Mac on January 11, 2011, 04:26:27 PM
my version
Code: [Select]
(atoi (substr (ver) 13))

Bravo  8-)
Title: Re: Detect AutoCAD version
Post by: alanjt 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).
Title: Re: Detect AutoCAD version
Post by: ronjonp 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:
Title: Re: Detect AutoCAD version
Post by: ronjonp on January 11, 2011, 04:38:33 PM
my version
Code: [Select]
(atoi (substr (ver) 13))

Bravo  8-)

X2
Title: Re: Detect AutoCAD version
Post by: alanjt 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.
Title: Re: Detect AutoCAD version
Post by: ElpanovEvgeniy on January 11, 2011, 04:47:37 PM
Mood has improved! Thank you :)
Title: Re: Detect AutoCAD version
Post by: ronjonp 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.
Title: Re: Detect AutoCAD version
Post by: did.ave on January 12, 2011, 04:53:41 AM
coucou

Evgeniy is always the most concise

i'm french, so I say merci

amicalement
Title: Re: Detect AutoCAD version
Post by: Chris 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.
Title: Re: Detect AutoCAD version
Post by: MeasureUp on January 12, 2011, 06:19:44 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.
X4 - I'm changing my code.
x5
Learned. It's very cool.