@john.uhden wrote:
.... you could make it easy by making the previous value the default so if the user wants to use the previous value, then all he has to do is hit Enter...
Let's say that the most popular value of sc1 is 3.45
(if (not sc1)(setq sc1 3.45))
(if (setq ans (getreal (strcat "\nSC1 <" (rtos sc1 2 2) ">: ")))
(setq sc1 ans)
)
And if you want to hold its latest value between drawings in one AutoCad session, use the vl-bb-set and vl-bb-ref functions, or write its value to a default file or into the registry.
There's a way to offer the previous setting as default if it exists, without that temporary [in this case 'ans'] variable, and even to incorporate an initial default value for Enter even on first use without presetting it if it doesn't exist yet, as done above, and all within one (setq) function. Let's say you want to offer an initial default of 100 if a value has not yet been set for sc1:
(setq sc1
(cond
( (getreal ; User input
(strcat
"\n* Enter Plot Scale <"
(if sc1 (rtos sc1 2 2) "100.00"); offer prior value as default if it exists, otherwise offer 100
">: "
); strcat
); getreal
); end User-input condition [returns nil on Enter, going on to:]
(sc1); Enter on subsequent use -- use prior value [nil if there isn't one, going on to:]
(100.0); Enter on first use -- no prior value; use initial default
); cond
); setq
An Environment Variable [via (setenv) / (getenv)] is another way to preserve the value across multiple editing sessions of the same drawing, and apply the same one across multiple drawings without having to set it in each. But if it's a plot scale, presumably you wouldn't want it applied at the same value in all drawings.
Other considerations:
Since sc1 is a plot scale, might it be extractable from something like the DIMSCALE System Variable, rather than having to ask the User for it?
Is there any reason not to simplify the calculations for the sc2 and th variables? [It seems odd to multiply something by 1.] Adjusting from Post 9:
(if (not sc1)
(setq
sc1 (getreal "\n* Enter Plot Scale : ")
sc2 (/ sc1 200)
th (/ sc1 500)
); setq
); if
Those divisors can be integers [not like the original 1000.0 with decimal], since sc1 will be a real number. Which raises the question: would sc1 always be a whole number [which seems likely for plot scales]? If so, should it use (getint) instead? If changed to that, the offered default in the (cond) above should be:
(if sc1 (itoa sc1) "100"); offer prior value as default if it exists, otherwise offer 100
and the Enter-on-first-use default should be:
(100); Enter on first use -- no prior value; use initial default
and those divisors in calculating sc2 and th should both be real numbers, or at some scales the sc2 and th values will come out wrong.
Kent Cooper, AIA