[lisp] Calculation not going r
Hi,I'm trying to get an avarage height between 2 z-values.However in the calculation part i geta 'error: bad function: "11.30"' error (height of first point in this case).
As far as i can tell my calculation part seems to be right, but it won't seem to accept the value.
What is going wrong?
(Defun c:zavg (/ punta puntb za zb tot avg)(setq punta (getpoint "\nKies het eerste punt"))(setq puntb (getpoint "\nKies het tweede punt"))(setq za (caddr (trans punta 1 0)) za (rtos za 2 2))(setq zb (caddr (trans puntb 1 0)) zb (rtos zb 2 2))(setq tot (+ za zb))(setq avg (/ tot 2))(princ avg)) You are trying to add two strings! First do the math, then convert them to strings. Removing the rtos part seem to do the trick .
(Defun c:zavg (/ punta puntb za zb tot avg)(setq punta (getpoint "\nKies het eerste punt:"))(setq puntb (getpoint "\nKies het tweede punt:\n"))(setq za (caddr (trans punta 1 0)))(setq zb (caddr (trans puntb 1 0)))(setq tot (+ za zb))(setq avg (/ tot 2))(acet-ui-status (strcat "Hoogte 1e punt: "(rtos za)"\nHoogte 2e punt: "(rtos zb)"\nDe gemiddelden hoogte is: " (rtos avg 2 2)) "Gemiddelde hoogte")(princ))
Thanks. Hi,
You did convert the variables (za & zb) to strings then you are trying to sum the two values and that is the error message that the program indicating to.
One solution:
(setq tot (+ (distof za) (distof zb))) Like others you used getpoint which is xyz and you want it as numbers so no Rtos, end result may need a rtos to make the (princ (strcat "average is " (rtos avg 2 2)))
页:
[1]