MarcoW Posted August 11, 2010 Share Posted August 11, 2010 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) ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 11, 2010 Share Posted August 11, 2010 Give this a try ..... (mapcar 'setvar '(cmdecho cursorsize xdwgfadectl savetime dimassoc cmdecho) '( 0 100 20 3 1 CmdEchoOld) ) Regards, Tharwat Quote Link to comment Share on other sites More sharing options...
MSasu Posted August 11, 2010 Share Posted August 11, 2010 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, Quote Link to comment Share on other sites More sharing options...
David Bethel Posted August 11, 2010 Share Posted August 11, 2010 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 Quote Link to comment Share on other sites More sharing options...
Kerry Brown Posted August 11, 2010 Share Posted August 11, 2010 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 sysvarlist nil 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 and Turns on PICKADD. Shift-Pick to remove ("PICKAUTO" 1) ; save current and Draws a selection window (for either a window or a crossing selection) automatically ("PICKBOX" 5) ; save current and initial is 3. my default is 6 ("INSUNITS" 0) ; save current and Unspecified (No units) ("SORTENTS" 1) ; save current and use 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))) Quote Link to comment Share on other sites More sharing options...
Se7en Posted August 11, 2010 Share Posted August 11, 2010 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 Quote Link to comment Share on other sites More sharing options...
MarcoW Posted August 11, 2010 Author Share Posted August 11, 2010 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! Quote Link to comment Share on other sites More sharing options...
Kerry Brown Posted August 11, 2010 Share Posted August 11, 2010 So much nicer. What was i thinking? thx If I'd had known you'd be perusing the code I'd probably have used OR Quote Link to comment Share on other sites More sharing options...
Se7en Posted August 11, 2010 Share Posted August 11, 2010 *blink* before last comment: much respect for Kerry | ---x---------------------- | *meow* after last comment: much respect for Kerry | -------------------------x | *meow* *lol* Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 11, 2010 Share Posted August 11, 2010 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) Quote Link to comment Share on other sites More sharing options...
Kerry Brown Posted August 11, 2010 Share Posted August 11, 2010 How about evaluation of quoted expressions: Personally I don't like seperated key and value lists .. too error prone and problematic to debug Quote Link to comment Share on other sites More sharing options...
BIGAL Posted August 12, 2010 Share Posted August 12, 2010 My five cents worth all the above are good ideas but I would make what your trying to do 2 defuns (newvars) & (oldvars) you will probably find that you want to do this same thing in lots of your code. Just put the defuns into a master lisp that loads at startup then each new program you only need to (newvars) at end (oldvars) I have a particular suite of 92 lisps and use this method all the time and then there are no mistakes and scratching of head as to why something doesn't work or went on the wrong layer (have a external customisable layer system) a particular area is "units" there are multiple setvars sometimes to be changed. Quote Link to comment Share on other sites More sharing options...
Kerry Brown Posted August 12, 2010 Share Posted August 12, 2010 Yep, that works fine untill you need to address a couple or 6 variables that you don't usually worry about ... and to handle their restoration at completion/error. I don't see anything wrong or incorrect with the OP's intention. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.