PDA

View Full Version : Predefined values



pintech
18th May 2005, 12:45 am
Can anyone tell what sould I do to have predefined values in a setq?

For example:
I create a:(setq a (getreal "base side:")

And I would like the autocad to show this:

base side: <5>

Is it possible?

I think is something like this but its not working:
(setq a (getreal "base side:" )
(cond ((null a) (setq a 5))

is it correct?
Thanks

CarlB
18th May 2005, 01:12 am
Your code works for me when the parentheses are corrected:

(setq a (getreal "base side:" ))
(cond ((null a) (setq a 5))

A general approach to a default input value might be:

(setq Default 5)
(setq BasePrompt (strcat "\nBase side<" (rtos Default 2 2) ">: "))
(setq a (getreal BasePrompt))
(if (null a) (setq a Default))

pintech
18th May 2005, 01:57 am
which is the best way?

pintech
18th May 2005, 02:03 am
My way works in your acad?

(setq a (getreal "base side:" ))
(cond ((null a) (setq a 5)))

for me just appears:

base side:

CarlB
18th May 2005, 02:12 am
By "works for me" I mean if I hit "enter" after the prompt for base, the "setq" works properly and 'a' is assigned a value of 5. It looks like you aren't hitting "enter", and AutoCAD is waiting for your response to "getreal". To include the "5" in the prompt, refer to my example.

pintech
18th May 2005, 02:44 am
ok I think I got it
Thanks

pintech
18th May 2005, 02:52 am
So why is this not working with me?


(defun solido ()
(setq r1 (getdist "\n larger radius <10>: ")
(cond ((null r1) (setq r1 10)))
r2 (getdist "\n smaller radius <2>: ")
(cond ((null r2) (setq r2 2)))
h (getdist "\n height <20>: ")
(cond ((null h) (setq h 20)))
sides (getint "\n number of polygon sides <3>: ")
(cond ((null sides) (setq sides 3)))
centerpt (getpoint "\n insertion point: ")
osnaps (getvar "osmode")
ang (atan (* (/ (- r1 r2) h) (cos (/ PI sides))))

) ; end setq

(setvar "osmode" 0)
(command "polygon"
sides
centerpt
"I"
(polar centerpt 0 r1)
)
(command "extrude" (entlast) "" h (/ (* ang 180.0) pi ))
(setvar "osmode" osnaps)
(setq vol (entlast))
(list r1 r2 h sides centerpt)
(command "zoom" "ex")
;(solint)
) ;end defun solido

CarlB
18th May 2005, 03:54 am
Hi pintec, how are you and Bacon doing on your assignment deadline ? :)

As to your question.....because your setq syntax is not correct. You can't have a continuous setq statement with "conds" in between. Close each setq-

(defun solido ()
(setq r1 (getdist "\n larger radius <10>: "))
(cond ((null r1) (setq r1 10)))
(setq r2 (getdist "\n smaller radius <2>: "))
(cond ((null r2) (setq r2 2)))
(setq h (getdist "\n height <20>: ") )
(cond ((null h) (setq h 20)))
(setq sides (getint "\n number of polygon sides <3>: "))
etc......

**********Or change your cond statement line;

(defun solido ()
(setq r1 (getdist "\n larger radius <10>: ")
r1 (if (null r1) 10 r1)
r2 (getdist "\n smaller radius <2>: ")
r2 (if (null r2) 2 r2)
etc....

pintech
18th May 2005, 09:14 am
Hi pintec, how are you and Bacon doing on your assignment deadline ?

What do you mesn with assignment deadline?

Thanks for the correction