PDA

View Full Version : Lisp tweak: getting default value to work



jsr13
2006-11-23, 06:27 AM
What the routine does:
On a structural foundation plan, you type in the size of a square column footing (or select default values), select the column (osnap preset to "insert"), then select the location of the footing callout (ftgcallout.dwg) that is scaled per the dimscale. The "ftgcallout.dwg is attributed and the size is filled in from the size you determined back at the beginning of the routine.

The routine works fine except for one thing. The default settings for the footing sizes are "4" for the foot part and "0" for the inch part (for a 4'-0" square footing). In testing this, I can enter through the foot part with no problems, but when I try to hit enter for zero inches I get this message:

-------------------------
Command: PF
Enter footing size for FEET <4>:
Enter footing size for INCHES <0>:
; error: An error has occurred inside the *error* functionAutoCAD variable
setting rejected: "clayer" nil
------------------------

I can type the zero for inches & it works fine, but just hitting "enter" to select the default is killing it.

I have attached the lisp file, the attributed block that it inserts, and a screenshot of the finished product.

============

Thanks in advance for any help on this one.

Also, please bear in mind that I am 100% self-taught when it comes to Lisp, so my code might be a little bit on the rough side.

:banghead: :?:

kpblc2000
2006-11-23, 09:02 AM
To get "default" values try to use code like this:

(setq ftg_sz_ft (cond ((getint "\n Enter footing size for FEET <4>: "))
(t 4)
) ;_ end of cond
ftg_sz_in (cond ((getint "\n Enter footing size for INCHES <0>: "))
(t 0)
) ;_ end of cond
) ;_ end of setq

CAB2k
2006-11-23, 01:45 PM
You are also having a problem with the error handler. It is expecting a variable 'clayer' to be a string. You have used 'cly' and should be 'clayer' for the error handler to work properly.

Avatart
2006-11-23, 02:08 PM
The way I deal with default settings is to have them as global variables (ie not declared) and run a test at the beginning of the routine to see if these values are nil, if they are, I supply my default value, if they are not, I apply my preset value to the prompt string.

Like this:

(if (= cp_width nil) (setq cp_width 2400.0))
(setq widthnew (getreal (strcat "\nEnter Bay Width (" (rtos cp_width) "): ")))

Then your program can remember the last settings that you made. I try and avoid doing this too often, as it clutters the open drawing with global variables.

jsr13
2006-11-23, 03:47 PM
Thank you ALL for your input.

KPBLC2000:
Your code worked for me the first time I put it in - defaults work without a hitch now. Bravo.

CARL_HD_COLLINS:
I definitely see your logic, but I've never programmed one to "remember" last settings. You're saying that the 2nd time that I go into the routine that the default shown would be whatever I chose the 1st time, but I would still be able to change the value. Correct?

Avatart
2006-11-23, 03:50 PM
CARL_HD_COLLINS:
I definitely see your logic, but I've never programmed one to "remember" last settings. You're saying that the 2nd time that I go into the routine that the default shown would be whatever I chose the 1st time, but I would still be able to change the value. Correct?That is exactly it, if you have a routine that you will use a number of times in the same editing session and that memory would be useful, then this is a suitable approach.

It won't remember between editing sessions and would not be suitable if your defaults should always apply.

jsr13
2006-11-23, 04:05 PM
That is exactly it, if you have a routine that you will use a number of times in the same editing session and that memory would be useful, then this is a suitable approach.

It won't remember between editing sessions and would not be suitable if your defaults should always apply.
-------------------

Great. I guess what I don't get is the "widthnew" in your example and how to incorporate it correctly. I've adapted what you showed to include the two default values that I need to retain:

(if (= ftg_sz_ft nil) (setq ftg_sz_ft 4))
(setq widthnew_ft (getreal (strcat "\nEnter Footing Width FEET (" (rtos ftg_sz_ft) "): ")))
(if (= ftg_sz_in nil) (setq ftg_sz_in 0))
(setq widthnew_in (getreal (strcat "\nEnter Footing Width INCHES (" (rtos ftg_sz_in) "): ")))

Am I headed in the right direction?

Avatart
2006-11-23, 04:18 PM
-------------------

Great. I guess what I don't get is the "widthnew" in your example and how to incorporate it correctly. I've adapted what you showed to include the two default values that I need to retain:

(if (= ftg_sz_ft nil) (setq ftg_sz_ft 4))
(setq widthnew_ft (getreal (strcat "\nEnter Footing Width FEET (" (rtos ftg_sz_ft) "): ")))
(if (= ftg_sz_in nil) (setq ftg_sz_in 0))
(setq widthnew_in (getreal (strcat "\nEnter Footing Width INCHES (" (rtos ftg_sz_in) "): ")))

Am I headed in the right direction?Sorry, that is just me being lazy and pasting out of another app that I wrote. You can use your ftg_sz_ft and ftg_sz_in variables.

CAB2k
2006-11-24, 01:58 PM
This is how I usually handle it:

(or ftg_size (setq ftg_size 48.0))
(setq ftg_size
(cond ((getdist (strcat "nEnter or pick Footing Width (" (rtos ftg_size) "): ")))
(ftg_size)))

(setq ftg_sz_in (rem ftg_size 12.0))
(setq ftg_sz_ft (fix (/ ftg_size 12)))

You may enter 48 or 4'0 or 24'6" or pick the distance in the drawing.

jsr13
2006-11-27, 05:37 AM
OK - now I'm lost trying to follow two very different (?) paths. Maybe not so different?

CAB: I have to ask where you got the variable "ftg_size" and from & why?

Carl: I think I see where you're going with the "widthnew_ft" & "widthnew_in" part:
The default value is set as "ftg_sz_ft". If I want the default, I hit enter & the default becomes "widthnew_ft". If I don't want the default, I type in the value for "widthnew_ft" but later on it must revert to "ftg_sz_ft" so it will be the default the next time I run the routine. Am I getting closer?

--------------------------

I think my "self-training" needs a little more "self-training." I hope I'm not really as dense as I sound.

Thanks again, guys.

Avatart
2006-11-27, 09:13 AM
OK - now I'm lost trying to follow two very different (?) paths. Maybe not so different?
Carl: I think I see where you're going with the "widthnew_ft" & "widthnew_in" part:
The default value is set as "ftg_sz_ft". If I want the default, I hit enter & the default becomes "widthnew_ft". If I don't want the default, I type in the value for "widthnew_ft" but later on it must revert to "ftg_sz_ft" so it will be the default the next time I run the routine. Am I getting closer?
Closer? You're spot on!

CAB2k
2006-11-27, 05:25 PM
CAB: I have to ask where you got the variable "ftg_size" and from & why?


I made it up :)
It allows the user to enter the entire width in one statement.
Like 2'4" or 2'4 or 2'-4" or 28 or 28"
OR you may pick the distance in the drawing.

It is much easer on the use IMO.