Jump to content

[lisp] Calculation not going right.


OMEGA-ThundeR

Recommended Posts

Hi,

 

I'm trying to get an avarage height between 2 z-values. However in the calculation part i get a '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)
)

Link to comment
Share on other sites

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.

Edited by OMEGA-ThundeR
Link to comment
Share on other sites

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)))

Link to comment
Share on other sites

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)))

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...