PDA

View Full Version : Best wat to create a list using function CONS


madcadder
2007-06-17, 07:26 PM
I have this series of code for the beginning of a routine:
(VL-LOAD-COM) ; loads ActiveX support if not already loaded
(SETQ |active-document| (vla-get-activedocument (vlax-get-acad-object)))

;;; Create list of original values for variables
(MAPCAR (FUNCTION
(LAMBDA (|variable-name|)
(SETQ |value| (CONS (CONS |variable-name| (GETVAR |variable-name|))
|value|
)
)
)
)
'("aunits" "attdia" "cecolor" "celtscale" "celtype" "celweight" "clayer" "cmdecho" "cmljust" "cmlscale" "cmlstyle" "dimstyle" "errno" "expert" "filedia" "filletrad" "hpang" "hpbound" "hpdouble" "hpname" "hpscale" "lunits" "luprec" "plinetype" "plinewid" "texteval" "textsize" "textstyle"
)
)
(vla-startundomark |active-document|)
Everything works correctly, or so it appears, but this was my output when retesting years later.


The list doesn't look right with all the dups. That wasn't the intent.

fixo
2007-06-17, 08:01 PM
Try this instead


(mapcar (function
(lambda (|variable-name|)
(cons |variable-name| (getvar |variable-name|))

)
)

'("aunits" "attdia" "cecolor" "celtscale" "celtype" "celweight" "clayer" "cmdecho" "cmljust" "cmlscale" "cmlstyle" "dimstyle" "errno" "expert" "filedia" "filletrad" "hpang" "hpbound" "hpdouble" "hpname" "hpscale" "lunits" "luprec" "plinetype" "plinewid" "texteval" "textsize" "textstyle"
)
)


~'J'~

madcadder
2007-06-18, 12:36 AM
Edit: ahh... That works on it's own, but you showed me the light.

I had one too many CONs and just couldn't see it.

I need:

(MAPCAR (FUNCTION
(LAMBDA (|variable-name|)
(SETQ |value| (CONS |variable-name| (GETVAR |variable-name|))

)
)
)
'("aunits" "attdia" "cecolor" "celtscale" "celtype" "celweight" "clayer" "cmdecho" "cmljust" "cmlscale" "cmlstyle"
"dimstyle" "errno" "expert" "filedia" "filletrad" "hpang" "hpbound" "hpdouble" "hpname" "hpscale" "lunits"
"luprec" "plinetype" "plinewid" "texteval" "textsize" "textstyle"
)
)

I need to keep the list stored in |value| to be used later.

kpblc2000
2007-06-18, 06:25 AM
(setq |value| (mapcar (function
(lambda (|variable-name|)
(cons |variable-name| (getvar |variable-name|))
) ;_ end of lambda
) ;_ end of function
'("aunits" "attdia" "cecolor"
"celtscale" "celtype" "celweight"
"clayer" "cmdecho" "cmljust"
"cmlscale" "cmlstyle" "dimstyle"
"errno" "expert" "filedia"
"filletrad" "hpang" "hpbound"
"hpdouble" "hpname" "hpscale"
"lunits" "luprec" "plinetype"
"plinewid" "texteval" "textsize"
"textstyle"
)
) ;_ end of mapcar
) ;_ end of setq
In order to use lately you can use and |value|, and (mapcar 'car |value|)