TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: JohnK on March 06, 2020, 08:15:52 AM

Title: Turning off reconciled layers
Post by: JohnK on March 06, 2020, 08:15:52 AM
After about 10 years of not using AutoCAD I have a small AutoCAD Job and I could use a little help clearing out the fuzz. Please tell me if I am wrong.

First topic is Reconciled layers. I used to set LAYEREVAL to 0 but now it appears that it has been replaced with LAYERVALCTL? I penned the following code and have it in one of my start up files, is is correct? It seems to work but I don't know if I have the right version numbers or even the right variable(s) for what I want to do -i.e. turn reconciled layers off.

Code - Auto/Visual Lisp: [Select]
  1.   ((> 21 (atoi (getvar 'acadver)))
  2.      ;; AutoCAD 2008 and older
  3.      (setvar 'LAYEREVAL 0)
  4.      (setvar 'LAYERNOTIFY 0))
  5.   ((< 21 (atoi (getvar 'acadver)))
  6.      (setvar 'LAYEREVALCTL 0))
  7.   )
Title: Re: Turning off reconciled layers
Post by: Lee Mac on March 06, 2020, 08:29:08 AM
FWIW, rather than relying on AutoCAD version numbers (which then need to be subsequently maintained), I find it is usually easier to test whether a system variable exists by performing a getvar prior to the setvar, e.g.:
Code - Auto/Visual Lisp: [Select]
  1. (foreach v '(layereval layernotify layerevalctl)
  2.     (if (getvar v) (setvar v 0))
  3. )

Title: Re: Turning off reconciled layers
Post by: JohnK on March 06, 2020, 08:45:44 AM
Nice. Thank you!

A bit of a sidebar then (trying to de-fuzz my AutoLisp skills too). Wouldn't it be better/same to ignore the getvar portion and just wrap up the setvars in a cond? -i.e. This is obviously a pretty small portion of code so I'm not going after "speed improvements" per se; I'm only trying to remember coding nuances.

Code - Auto/Visual Lisp: [Select]
  1.   ( (setvar 'LAYEREVAL 0) )
  2.   ( (setvar 'LAYERNOTIFY 0) )
  3.   ( (setvar 'LAYEREVALCTL 0) )
  4.   )
Title: Re: Turning off reconciled layers
Post by: JohnK on March 06, 2020, 09:02:00 AM
On second thought: If the variable doesn't exist the evaluation of the COND statements will fail. Right?
Title: Re: Turning off reconciled layers
Post by: ronjonp on March 06, 2020, 11:38:01 AM
On second thought: If the variable doesn't exist the evaluation of the COND statements will fail. Right?
If that first ( (setvar 'LAYEREVAL 0) ) exists then the subsequent two lines will not get evaluated.
Title: Re: Turning off reconciled layers
Post by: JohnK on March 06, 2020, 11:47:27 AM
On second thought: If the variable doesn't exist the evaluation of the COND statements will fail. Right?
If that first ( (setvar 'LAYEREVAL 0) ) exists then the subsequent two lines will not get evaluated.

...And that too. Glad I asked, I'm obviously, very rusty. Thanks.

Quote
...until one of these items returns a value other than nil.
Title: Re: Turning off reconciled layers
Post by: Lee Mac on March 06, 2020, 02:43:27 PM
On second thought: If the variable doesn't exist the evaluation of the COND statements will fail. Right?

Exactly - setvar with an unknown system variable does not fail gracefully like getvar does, e.g.:
Code - Auto/Visual Lisp: [Select]
  1. _$ (setvar "se7en" 0)
  2. ; error: AutoCAD variable setting rejected: "se7en" 0
Title: Re: Turning off reconciled layers
Post by: JohnK on March 06, 2020, 03:00:53 PM
Well, that example just doesn't make any sense whatsoever--that variable should be accepted by most cad programs--but I see that now. ...Thanks. One small (tiny, mostly useless) bit of code, after a while away from AutoLisp, and the frustrations with the language start again. :)