Not difficult (if you know how
Just for the learningprocess, not for the worthy of the routine...How can I make the repetitive "setvar" more appropriate?
Like (setvar '("cursorsize" 1 "xdwgfadectl" 20 ... etc...
I have no clue allthough I remember seeing it somewhere..
Any help is appreciated, again, this is to learn only.
Here my code:
(defun c:hsh ( / CmdEchoOld) (setq CmdEchoOld (getvar "cmdecho") ) (setvar "cmdecho" 0) (setvar "cursorsize" 100) (setvar "xdwgfadectl" 20) (setvar "savetime" 3) (setvar "dimassoc" 1) (setvar "cmdecho" CmdEchoOld) (princ)) Give this a try .....
(mapcar 'setvar '(cmdecho cursorsize xdwgfadectl savetime dimassoc cmdecho) '( 0 100 20 3 1 CmdEchoOld) )
Regards,
Tharwat In SETVAR or SET you cannot use multiple assignments like in SETQ statement. You may use a list of pairs variable - value:
(foreach VariableSet '(("cmdecho" . 0) ("cursorsize" . 100) ("xdwgfadectl" . 20) ("savetime" . 3) ("dimassoc" . 1))(setvar (car VariableSet) (cdr VariableSet)))
Regards, I prefer making a list of dotted pairs
(setq var '(("CMDECHO" . 0) ("MENUECHO" . 0) ("MENUCTL" . 0) ("MACROTRACE" . 0) ("OSMODE" . 0) ("SORTENTS" . 119) ("LUPREC" . 2) ("MODEMACRO" . ".") ("BLIPMODE". 0) ("EXPERT" . 5) ("SNAPMODE". 1) ("PLINEWID" . 0) ("ORTHOMODE" . 1) ("GRIDMODE" . 0) ("ELEVATION" . 0) ("THICKNESS". 0) ("FILEDIA" . 0) ("FILLMODE" . 0) ("SPLFRAME". 0) ("UNITMODE" . 0) ("TEXTEVAL". 0) ("ATTDIA" . 0) ("AFLAGS" . 0) ("ATTREQ" . 1) ("ATTMODE" . 1) ("UCSICON" . 1) ("HIGHLIGHT" . 1) ("REGENMODE". 1) ("COORDS" . 2) ("DRAGMODE" . 2) ("DIMZIN" . 1) ("PDMODE" . 0) ("CECOLOR" . "BYLAYER") ("CELTYPE" . "BYLAYER")))(foreach v var(and (getvar (car v)) (setq rst (cons (cons (car v) (getvar (car v))) nw_rst)) (setvar (car v) (cdr v))))
The list rst contains the prior settings so that you can easily rest the variables back to their original values.-David Similar to others : I had a phone call in the middle of putting it together
(setq CmdEchoOld (getvar "cmdecho") varsList (list '("cursorsize" . 1) '("xdwgfadectl". 20) '("cmdecho" . 0) '("cursorsize" . 100) '("xdwgfadectl" . 20) '("savetime" . 3) '("dimassoc" . 1) (cons "cmdecho" CmdEchoOld) ))(foreach item varsList (setvar (car item) (cdr item)))
or perhaps
(setq sysvarlistnil generalVars '(("CMDECHO" 0) ; save current and Turns off echoing ("expert" 5) ; save current value and set ("ORTHOMODE") ; save current value ("SNAPANG") ; save current value ("UCSICON") ; save current value ("SNAPMODE") ; save current value ("OSMODE") ; save current value ("CLAYER") ("PICKADD" 2) ; save current andTurns on PICKADD. Shift-Pick to remove ("PICKAUTO" 1) ; save current andDraws a selection window (for either a window or a crossing selection) automatically ("PICKBOX" 5) ; save current andinitial is 3. my default is 6 ("INSUNITS" 0) ; save current andUnspecified (No units) ("SORTENTS" 1) ; save current anduse selection Order to control ))(vars_list '(("cursorsize" . 1) ''("xdwgfadectl" . 20))) (foreach item (append vars_list generalVars) (setq sysvarlist (cons (list (car item) (getvar (car item))) sysvarlist ) ) (if (cadr item) (setvar (car item) (eval (cadr item))) ) );;---------;; do code mojo;;---------;; clean up(foreach item sysvarlist (setvar (car item) (cadr item))) oh!?Kerry you're a genius.
You had:
(if (cadr item) (setvar (car item) (eval (cadr item))) )
I had:
(if (cadr x) (if (not (eq (type (cadr x)) 'LIST)) (setvar (car x) (cadr x)) (setvar (car x) (eval (cadr x))) ) )
So much nicer. What was i thinking?
thx Thanks everybody!!
That shure is a big help. I will explore the differences and what may suit me best.
Tharwats reply whas exactly what I meant but maybe the other options are more convenient..?
I will try some coding. WHat I want to keep is an easy view.... if you get what I mean.
In such case the other options seem better "readable".
Thanks again for the good examples!
If I'd had known you'd be perusing the code I'd probably have used OR *blink*
before last comment:
much respect for Kerry | ---x---------------------- | *meow*
after last comment:
much respect for Kerry | -------------------------x | *meow*
*lol* How about evaluation of quoted expressions:
(setq StoredList (mapcar (function (lambda ( SystemVariable ) (list (quote setvar) SystemVariable (getvar SystemVariable)) ) ) (setq SystemVariables '( "CMDECHO" "OSMODE" "BLIPMODE" "FILLMODE" ) ) ))(mapcar (function setvar) SystemVariables '( 0 256 0 1 ))(mapcar (function eval) StoredList)
页:
[1]
2