TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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
-
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
((= (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))
-
(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)
)
)
-
(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)
)
)
)
)
-
Hi, maybe this can help
(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
)
-
Another approach ... although I'm sure it can be broken :-D
(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"
-
Another approach ... although I'm sure it can be broken :-D
(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"
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.
-
Another approach ... although I'm sure it can be broken :-D
(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"
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:
(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)
-
Another approach ... although I'm sure it can be broken :-D
(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"
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:
(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...
(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))
)
)
)
)
-
personally I prefer this:
(atoi (vl-string-right-trim " (en)" (vl-string-left-trim "Visual LISP " (ver))))
-
personally I prefer this:
(atoi (vl-string-right-trim " (en)" (vl-string-left-trim "Visual LISP " (ver))))
(defun getacadversion (/)
(vl-list->string
(vl-remove-if-not (function (lambda (x) (and (> x 47) (< x 58)))) (vl-string->list (ver)))
)
)
-
:ugly:
(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)
)
)
)
)
-
:ugly:
(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.
-
LoL, I think I'll stick with (getvar 'ACADVER).
:-D Me too :-)
-
my version
(atoi (substr (ver) 13))
-
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
((= (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))
-
my version
(atoi (substr (ver) 13))
Bravo 8-)
-
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
((= (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).
-
personally I prefer this:
(atoi (vl-string-right-trim " (en)" (vl-string-left-trim "Visual LISP " (ver))))
(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:
-
my version
(atoi (substr (ver) 13))
Bravo 8-)
X2
-
my version
(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.
-
Mood has improved! Thank you :)
-
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.
-
coucou
Evgeniy is always the most concise
i'm french, so I say merci
amicalement
-
my version
(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.
-
my version
(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.