View Full Version : lisp for checking and changing the "insunits"
d.luinstra
2009-04-09, 10:56 AM
Hello,
I'm new in lisp, to start I want to check if the insunits of the drawing is set on 2. If so, I want to change it to 0.
--------
(defun c:uc ()
(if (/= (getvar "insunits") 2) (setvar "insunits" 0))
); defun
--------
The problem is that the lisp doesn't work. Have I forgotten something?
After a few minutes of thinking, I think I should change the lisp to do the following:
- if insunits = 0 or 4 or 6 --> do nothing
- if insunits = other then 0 or 4 or 6 then do: (setvar "insunits" 0)
Only, I don't know how to program it in lisp.
icbinr
2009-04-09, 03:17 PM
I think this is what you are looking for.
(if
(not
(or
(= (getvar "INSUNITS") 0)
(= (getvar "INSUNITS") 4)
(= (getvar "INSUNITS") 6)
)
)
(setvar "INSUNITS" 0)
(princ)
)
Add it to your ACADDOC.LSP and it will check each drawing when you open it.
After I looked at it... You can do it without the NOT also.
(if
(or
(/= (getvar "INSUNITS") 0)
(/= (getvar "INSUNITS") 4)
(/= (getvar "INSUNITS") 6)
)
(setvar "INSUNITS" 0)
(princ)
)
msretenovic
2009-04-15, 05:02 AM
I think this is what you are looking for.
(if
(not
(or
(= (getvar "INSUNITS") 0)
(= (getvar "INSUNITS") 4)
(= (getvar "INSUNITS") 6)
)
)
(setvar "INSUNITS" 0)
(princ)
)
Add it to your ACADDOC.LSP and it will check each drawing when you open it.
After I looked at it... You can do it without the NOT also.
(if
(or
(/= (getvar "INSUNITS") 0)
(/= (getvar "INSUNITS") 4)
(/= (getvar "INSUNITS") 6)
)
(setvar "INSUNITS" 0)
(princ)
)
Here is an alternative:
(if (not (member (getvar "INSUNITS") (list 0 4 6)))
(setvar "INSUNITS")
(princ)
)
I would find this a little easier to maintain as the values to check can be updated in the list as opposed to adding or subtracting conditional statements. :)
However, the first may be more clear to read and understand.
d.luinstra
2009-04-15, 01:07 PM
Thanks!!
I've put the following in the acaddoc.lsp, It's working great!!!
(if
(not
(or
(= (getvar "INSUNITS") 0)
(= (getvar "INSUNITS") 4)
(= (getvar "INSUNITS") 6)
)
)
(setvar "INSUNITS" 0)
(princ)
)
CadDog
2009-04-15, 10:32 PM
We just use (setvar "insunits" 0) in all cases
and teach all new AutoCAD users the 1/12.
What way in civil the border (title block) which are drawn in inches are insert right as well as our Arch and Civil xref. (using 1/12 when needed)
Nice feature
NOT...!!!
rkmcswain
2009-04-15, 10:38 PM
Thanks!!
I've put the following in the acaddoc.lsp, It's working great!!! Also, remember that changing INSUNITS also changes DBMOD.
msretenovic
2009-04-15, 11:35 PM
Also, remember that changing INSUNITS also changes DBMOD.
To get around changing DBMOD, you can always do this:
(acad-push-dbmod)
(if (not (member (getvar "INSUNITS") (list 0 4 6)))
(setvar "INSUNITS" 0)
)
(acad-pop-dbmod)
(princ);)
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.