Code Red > AutoLISP (Vanilla / Visual)
how can i keep settings
masao:
my cad is 2012 and i use dimcenter must set layer and color.
i have a question,if i missed circle select setting would back(i have *error*code so i missed select would enter *error*code)
if must make a code by yourself, i cant get "circle or arc on block" center point.
--- Code: ---(defun C:CTR (/ e_lst ocolor oltype odimcen)
(setq e_lst (mapcar (function (lambda (n) (list 'setvar n (getvar n)))) '("cecolor" "celtype" "dimcen")) )
(defun *error* (msg)
(mapcar 'eval e_lst)
(princ "")
)
(setvar "cmdecho" 0)
(if (= (tblsearch "ltype" "center") nil)
(vl-cmdf "_.-linetype" "_load" "center" "acadiso.lin" "")
)
(vl-cmdf "_.-linetype" "_load" "center" "acadiso.lin" "_yes" "")
(while
(setq ocolor (getvar "cecolor")
oltype (getvar "celtype")
odimcen (getvar "dimcen")
)
(setvar "cecolor" "1")
(setvar "celtype" "CENTER")
(setvar "dimcen" -2)
(command "dimcenter" pause)
(setvar "cecolor" ocolor)
(setvar "celtype" oltype)
(setvar "dimcen" odimcen)
);while
(princ)
)
(princ)
--- End code ---
mhupp:
Here is a simple trick to store, set, and recall a list of system variables. (probably found on here)
--- Code - Auto/Visual Lisp: ---(defun C:CTR (/ vars vals) (setq vars '("cecolor" "celtype" "dimcen") ;list of variables vals (mapcar 'getvar vars) ;store old values in a list called vals ) (mapcar 'setvar vars '(1 "CENTER" -2)) ;set new values (setvar "cmdecho" 0) (if (= (tblsearch "ltype" "center") nil) (vl-cmdf "_.-linetype" "_load" "center" "acadiso.lin" "") ) (vl-cmdf "_.-linetype" "_load" "center" "acadiso.lin" "_yes" "") (command "dimcenter") (while (> (getvar 'cmdactive) 0) (vl-cmdf "\\")) ;waits for dimcenter command to finish (mapcar 'setvar vars vals) ;sets all values back to before (princ))
masao:
--- Quote from: mhupp on December 05, 2023, 08:04:19 AM ---Here is a simple trick to store, set, and recall a list of system variables. (probably found on here)
--- Code - Auto/Visual Lisp: ---(defun C:CTR (/ vars vals) (setq vars '("cecolor" "celtype" "dimcen") ;list of variables vals (mapcar 'getvar vars) ;store old values in a list called vals ) (mapcar 'setvar vars '(1 "CENTER" -2)) ;set new values (setvar "cmdecho" 0) (if (= (tblsearch "ltype" "center") nil) (vl-cmdf "_.-linetype" "_load" "center" "acadiso.lin" "") ) (vl-cmdf "_.-linetype" "_load" "center" "acadiso.lin" "_yes" "") (command "dimcenter") (while (> (getvar 'cmdactive) 0) (vl-cmdf "\\")) ;waits for dimcenter command to finish (mapcar 'setvar vars vals) ;sets all values back to before (princ))
--- End quote ---
thank you ,but can not use while loop.
if use while can not end loop.
JohnK:
Your error handler will restore the variables so all you have to do is invoke the error handler (which you can do with `QUIT`).
I have highlighted the lines that I changed.
--- Code - Auto/Visual Lisp: ---(defun C:CTR (/ e_lst ocolor oltype odimcen *error*) (defun *error* (msg) (mapcar 'eval e_lst) (princ "") ) (setq e_lst (mapcar (function (lambda (n) (list 'setvar n (getvar n)))) '("cecolor" "celtype" "dimcen")) ) (setvar "cmdecho" 0) (if (= (tblsearch "ltype" "center") nil) (vl-cmdf "_.-linetype" "_load" "center" "acadiso.lin" "") ) (vl-cmdf "_.-linetype" "_load" "center" "acadiso.lin" "_yes" "") (while (setq ocolor (getvar "cecolor") oltype (getvar "celtype") odimcen (getvar "dimcen")) (setvar "cecolor" "1") (setvar "celtype" "CENTER") (setvar "dimcen" -2) (command "dimcenter" pause) (setvar "cecolor" ocolor) (setvar "celtype" oltype) (setvar "dimcen" odimcen) );while (quit) (princ) )(princ)
masao:
--- Quote from: JohnK on December 05, 2023, 09:37:42 AM ---Your error handler will restore the variables so all you have to do is invoke the error handler (which you can do with `QUIT`).
I have highlighted the lines that I changed.
--- Code - Auto/Visual Lisp: ---(defun C:CTR (/ e_lst ocolor oltype odimcen *error*) (defun *error* (msg) (mapcar 'eval e_lst) (princ "") ) (setq e_lst (mapcar (function (lambda (n) (list 'setvar n (getvar n)))) '("cecolor" "celtype" "dimcen")) ) (setvar "cmdecho" 0) (if (= (tblsearch "ltype" "center") nil) (vl-cmdf "_.-linetype" "_load" "center" "acadiso.lin" "") ) (vl-cmdf "_.-linetype" "_load" "center" "acadiso.lin" "_yes" "") (while (setq ocolor (getvar "cecolor") oltype (getvar "celtype") odimcen (getvar "dimcen")) (setvar "cecolor" "1") (setvar "celtype" "CENTER") (setvar "dimcen" -2) (command "dimcenter" pause) (setvar "cecolor" ocolor) (setvar "celtype" oltype) (setvar "dimcen" odimcen) );while (quit) (princ) )(princ)
--- End quote ---
sorry ,this code has same result.
if i use CTR and missed click ,color and linetype has change old setting.
mhupp post code can prevent it,but can not use while to loop.
like cad code "*^C^C_dimcenter" can loop and missed click has not change old setting.
Navigation
[0] Message Index
[#] Next page
Go to full version