MarcoW 发表于 2022-7-6 10:33:59

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))

Tharwat 发表于 2022-7-6 10:42:17

Give this a try .....
 

(mapcar 'setvar '(cmdecho cursorsize xdwgfadectl savetime dimassoc cmdecho) '( 0 100 20 3 1 CmdEchoOld) )
 
Regards,
 
Tharwat

MSasu 发表于 2022-7-6 10:48:08

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,

David Bethel 发表于 2022-7-6 10:52:12

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

Kerry Brown 发表于 2022-7-6 10:56:58

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)))

Se7en 发表于 2022-7-6 11:02:53

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

MarcoW 发表于 2022-7-6 11:08:01

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!

Kerry Brown 发表于 2022-7-6 11:13:50

 
If I'd had known you'd be perusing the code I'd probably have used OR

Se7en 发表于 2022-7-6 11:15:15

*blink*
 
before last comment:
much respect for Kerry | ---x---------------------- | *meow*
 
after last comment:
much respect for Kerry | -------------------------x | *meow*
 
 
 
 
*lol*

Lee Mac 发表于 2022-7-6 11:19:47

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
查看完整版本: Not difficult (if you know how