TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: daron on February 16, 2004, 06:27:26 PM
-
I have this:
(setq var '("osmode" "clayer" "cmdecho"
"ltscale" "plinewid" "users1"
"users2" "users3")
val (mapcar 'getvar var)
)
and the only way I've found to get single values from single variables from anywhere in the code is this:
(setq num 0)
(foreach item var
(if (/= item "users3")
(setq num (1+ num))
(setq angv (nth num val))
)
)
I feel that a mapcar lambda should do the trick, but I couldn't get that to work.
-
Ok try this to set the variables in the list .....
(setq var '("osmode" "clayer" "cmdecho" "ltscale" "plinewid" "users1" "users2" "users3")
val (apply 'append (mapcar '(lambda (x) (list (cons (read x) (getvar x)))) var))
)
and this to retrieve a specific variable
(cdr (assoc 'USERS1 val))
The reason why I used (read x) is because it returns a string that is all caps and treated as an atom and is therefore able to be recognized regardless of capitalization of the request for value ...
hence..
(cdr (assoc 'USERS1 val))
(cdr (assoc 'users1 val))
(cdr (assoc 'UsErS1 val))
will all return the correct value.
If you attempt to do the following:
(cons X (getvar x))
you will have to match capitalization.
(cdr (assoc "users1" val))
Does this make sense??
-
Will this help? (test "users1")
(defun test (x / val var)
(setq var '("osmode" "clayer" "cmdecho"
"ltscale" "plinewid" "users1"
"users2" "users3")
)
(if (and (= (type x) 'STR)
(setq var (member x var))
)
(setq val (getvar (car var)))
)
val
)
-
Thanks. That helps a lot.
-
(nth (vl-position x var) val)
or ..
(nth (vl-position (strcase x)(mapcar 'strcase var)) val)
or .. Keith'ified
(nth (vl-position (read x) (mapcar 'read var)) val)
-
awwww.... I feel so speshul ...
Bein' how Stig cound a new word just for me....