(command "_.pedit" "_m" (LM:ssget "SELECTED..." (list "_W" sel1 sel2)) "" "_j" "" "")
Command: (#Error_Push_Vars '(("CDECHO" 0)))
; error: AutoCAD variable setting rejected: "CDECHO" 0
Command: (setq var '(cdecho)
(_> val (mapcar 'getvar var))
(nil)
It will error out, of course. -i.e. I understand yours will generate a nil list but which is worse for a programmer that may never notice they misspelled a variable: 1. blindly (re)set values assuming all is well or 2. code errors out upon load/run?
...if the procedure or developer needs a variable which isn’t available the rule is to “fail fast” because these errors are typically easier to find and fix.
....my point is that not all system variables are available in all versions of AutoCAD or on all platforms supporting a LISP API, hence if code is to be compatible across a wide range of releases, such differences need to be accounted for to avoid errors.
If a variable ( that retrieved from sys_var ) has a value, then that means the system variable is available then set the new desired value otherwise ignore the setting and resetting on exit.
Of course there is a goal behind using system variables to perform a certain process and of course you have the choice to use it or to leave it behind.
So you can ignore the use of CMDECHO then the history statements of the command used will be printed on the command line so we need it for a better presentation and performance of codes in this case.
Suppose the CMDECHO was not supported into your AutoCAD release and we want to use it, then how to know without testing out the return value of that sys_var to decide to set then reset ? So the main point resides here.
Edit: ...thought pattern.
Thanks for all the discussion. It helps seeing more accomplished ppl discuss varying ideas that us lesser beings might not ever see or understand.
I did question what lines 7 and 39 were doing. Totally as an assumption/guess I took it to mean if the variable exists as line 7 states, error, because it should really be as line 39 states. I certainly didn't take into account versions or platforms beyond my simple though pattern.
J. Logan
In the beginning of function I establish a list of the necessary environment variables,
list variable always miscellaneous:
Code:
(SETQ
ERROR-LST-
'("AUTOSNAP" "OSMODE" "APERTURE" "HPSPACE" "HPASSOC"
"MIRRTEXT" "AUPREC" "LUPREC" "DIMZIN" "cecolor")
ERROR-LST- (mapcar '(lambda (a) (list 'setvar a (getvar a))) ERROR-LST-)
)
Function *error*
Code:
(defun *error* (msg)
(MAPCAR 'eval ERROR-LST-))
It is a universal *error* function *smile*
The discussion was (in a nut-shell):Evgeniy's example contains the answer to the question
Lee introduced a feature in his version. I questioned the need for that feature.
I did question what lines 7 and 39 were doing. Totally as an assumption/guess I took it to mean if the variable exists as line 7 states, error, because it should really be as line 39 states. I certainly didn't take into account versions or platforms beyond my simple though pattern.
Those lines (36, 37, 38) in Lee's code are a slightly modified version of a wonderful generic error handler skeleton ElpanovEvgeniy posted years ago.