please help me , problem with my lisp

please help me , problem with my lisp

Anonymous
Not applicable
1,023 Views
18 Replies
Message 1 of 19

please help me , problem with my lisp

Anonymous
Not applicable

hello ,

I have a lisp , that must do these things:

1-select 1st and 2nd point of the line (as a wall)

2- calculate the distance of a wall 

2- find the direction of the wall 

3- ask me a height 

4- calculate the area (distance * height)

5- write the angle and area in drawing.

after I run the lisp, I can select 1st and 2nd point but, when it goes to direction , show this message "wall direction:; error: no function definition: RTOD" 

please Guide me . 

thanks

the lisp is attached.

sorry for my english🙏

0 Likes
1,024 Views
18 Replies
Replies (18)
Message 2 of 19

Shneuph
Collaborator
Collaborator

Have you defined "RTOD" as a function in some place?

 

It looks like you're trying to convert Radians to Degrees  RTOD isn't  built in AutoLISP function though.

 

You can define an function called RTOD or look into using CVUNIT

https://help.autodesk.com/view/OARX/2020/ENU/?guid=GUID-253E72F1-09B8-473E-A51B-B97BE2E29019

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
0 Likes
Message 3 of 19

john.uhden
Mentor
Mentor

angtos

John F. Uhden

0 Likes
Message 4 of 19

Shneuph
Collaborator
Collaborator

Wouldn't angtos cause it to perform a subtraction on a string?

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
0 Likes
Message 5 of 19

john.uhden
Mentor
Mentor
I'm sorry. I guess I misinterpreted. I had thought the OP wanted to
convert an angle in radians to degrees as a string. That's what angtos is
for.
I don't see any reason for converting an angle in radians to degrees as a
REAL, if that's what he was trying to do.
One can get used to dealing with radians pretty quickly when one realizes
that pi radians make half a circle (180°). I remember stumbling over that
and now it's like taking a pee.

John F. Uhden

0 Likes
Message 6 of 19

Sea-Haven
Mentor
Mentor

Maybe this 

;The dtr function converts degrees to radians
;The rtd function converts radians to degrees
(defun dtr (a)
(* pi (/ a 180.0))
)
;
(defun rtd (a)
(/ (* a 180.0) pi)
)

 

 

Message 7 of 19

Anonymous
Not applicable

then you think where is the problem?

 

;(command "layer" "m" "cal" "")
(if (= sang nil)
(progn (setq sang (getreal "\nSpecify site angle:"))
(if (= sang nil) (setq heit 0))
)
(progn (princ (strcat "\nSite angle is: " (rtos sang 2)))
(setq sngl (getreal "\nSpecify new site angle or enter:"))
)
)
(if (/= sngl nil) (setq sang sngl))

(defun c:cl ()

(princ (strcat "\nSite angle is: " (rtos sang 2)))

(setq 1stp (getpoint "\nfirst point:")
2ndp (getpoint 1stp "\nsecond point")
dis1 (/ (distance 1stp 2ndp) 1)

)

(command "line" 1stp 2ndp "")

(setq pntx (/ (+ (car 1stp) (car 2ndp)) 2)
pnty (/ (+ (car (cdr 1stp)) (car (cdr 2ndp))) 2)
3rdp (list pntx pnty)
angl (- (rtod (getangle 3rdp "\nwall direction:")) sang)
)

(if (< angl 0) (setq angl (+ 360 angl)))

(if (and (> angl 0.00) (<= angl 11.25)) (setq side "E"))
(if (and (> angl 11.25) (<= angl 33.75)) (setq side "ENE"))
(if (and (> angl 33.75) (<= angl 56.25)) (setq side "NE"))
(if (and (> angl 56.25) (<= angl 78.75)) (setq side "NNE"))
(if (and (> angl 78.75) (<= angl 101.25)) (setq side "N"))
(if (and (> angl 101.25) (<= angl 123.75)) (setq side "NNW"))
(if (and (> angl 123.75) (<= angl 146.25)) (setq side "NW"))
(if (and (> angl 146.25) (<= angl 168.75)) (setq side "WNW"))
(if (and (> angl 168.75) (<= angl 191.25)) (setq side "W"))
(if (and (> angl 191.25) (<= angl 213.75)) (setq side "WSW"))
(if (and (> angl 213.75) (<= angl 236.25)) (setq side "SW"))
(if (and (> angl 236.25) (<= angl 258.75)) (setq side "SSW"))
(if (and (> angl 258.75) (<= angl 281.25)) (setq side "S"))
(if (and (> angl 281.25) (<= angl 303.75)) (setq side "SSE"))
(if (and (> angl 303.75) (<= angl 326.25)) (setq side "SE"))
(if (and (> angl 326.25) (<= angl 348.75)) (setq side "ESE"))
(if (and (> angl 348.75) (<= angl 360)) (setq side "E"))

(if (= d_st nil)
(progn (setq d_st (getreal "\ninput wall height:"))
(if (= d_st nil) (setq heit 0))
)
(progn (princ (strcat "\nwall height is: " (rtos d_st 2)))
(setq hei2 (getreal "\ninput new height or enter:"))
)
)
(if (/= hei2 nil) (setq d_st hei2))

(setq dist (rtos (* dis1 d_st) 2 2)
dist (strcat side "=" dist)
)
(princ "\nSpecify start point of text:")
(command "text" "s" "standard" pause "0.5" "0" dist)
)


(defun c:pt ()

(setq 1stp (getpoint "\nfirst point:")
2ndp (getpoint 1stp "\nsecond point")
dis1 (/ (distance 1stp 2ndp) 10)

)

(command "line" 1stp 2ndp "")

(if (= d_st nil)
(progn (setq d_st (getreal "\ninput wall height:"))
(if (= d_st nil) (setq heit 0))
)
(progn (princ (strcat "\nwall height is: " (rtos d_st 2)))
(setq hei2 (getreal "\ninput new height or enter:"))
)
)
(if (/= hei2 nil) (setq d_st hei2))

(setq dist (rtos (* dis1 d_st) 2 2)
dist (strcat "part=" dist)
)
(princ "\nSpecify start point of text:")
(command "text" "s" "standard" pause "1" "0" dist)
)

;(defun c:aa ()
; (setq list nil
; pnt1 (getpoint "\nSpecify start point:")
; list (list pnt1)
; numb 1
; )
; (repeat 100
; (progn (setq pnt2 pnt1
; pnt1 (getpoint pnt2 "\nSpecify other point:")
; list (cons pnt1 list)
; numb (+ numb 1)
; )
;
; )
; )

 

(defun c:mtf ()
(setq mm (getreal "\ninput number:"))
(princ (* 10.768 mm))
)

 

 

0 Likes
Message 8 of 19

ВeekeeCZ
Consultant
Consultant

Something for fun and inspiration.

 

(defun c:WallsizeReset () (setq *wa-angs* nil) (c:Wallsize) (princ))

(defun c:Wallsize ( / 1stp 2ndp midp angw angt degt side)

  (or *wa-angs*
      (setq *wa-angs* (cond ((getangle "\nSite angle <0>: "))
			    (0))))
  (princ (strcat "\nCurrent site angle: " (angtos *wa-angs*)))

  (or *wa-hig*
	(setq *wa-hig* 0))

  (while (and (setq 1stp (getpoint "\nFirst point: "))
	      (setq 2ndp (getpoint 1stp "\nSecond point: "))
	      (setq midp (mapcar '/ (mapcar '+ 1stp 2ndp) '(2 2)))
	      (setq angw (getangle midp "\nWall direction: "))
	      )
    (setq angt (+ *wa-angs* angw)
	  angt (rem angt (* 2 pi))
	  degt (/ angt (* 2 pi))
	  side (cond ((<= degt 11.25) "E")
		     ((<= degt 33.75) "ENE")
		     ((<= degt 56.25) "NE")
		     ((<= degt 78.75) "NNE")
		     ((<= degt 101.25) "N")
		     ((<= degt 123.75) "NNW")
		     ((<= degt 146.25) "NW")
		     ((<= degt 168.75) "WNW")
		     ((<= degt 191.25) "W")
		     ((<= degt 213.75) "WSW")
		     ((<= degt 236.25) "SW")
		     ((<= degt 258.75) "SSW")
		     ((<= degt 281.25) "S")
		     ((<= degt 303.75) "SSE")
		     ((<= degt 326.25) "SE")
		     ((<= degt 348.75) "ESE")
		     ("E")))

    (setq *wa-hig* (cond ((getdist (strcat "\nWall height <" (rtos *wa-hig*) ">: ")))
			 (*wa-hig*)))
    (entmakex (list (cons 0 "TEXT") (cons 10 midp) (cons 40 (getvar 'textsize)) '(7 . "Standard")
		    (cons 1 (strcat "part=" (rtos (* (distance 1stp 2ndp) *wa-hig*) 2 2)" " side))))
    (command "_.move" "_l" "" midp pause))
  (princ)
  )
 
Message 9 of 19

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

then you think where is the problem?

....

angl (- (rtod (getangle 3rdp "\nwall direction:")) sang)

....


Try loading the (rtd) function in Message 6, and changing the rtod above to rtd to match the function's name.  [You could change the function's name to rtod instead, and leave your code alone, but rtd is a very commonly-used name for such a conversion function, and you will find other routines that use it.]

Kent Cooper, AIA
0 Likes
Message 10 of 19

Anonymous
Not applicable

hello 

so good thank you 👍

but it shows all the angels in "E"

I think we have to describe a range for that ?

0 Likes
Message 11 of 19

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....

but it shows all the angels in "E"

I think we have to describe a range for that ?


Should the 'degt' variable be calculated differently?  The 'angt' variable will be in radians.  If it's supposed to be in degrees for the range conditions, a typical conversion would be:

....
degt (/ (* angt 180) pi)
....

 

Kent Cooper, AIA
0 Likes
Message 12 of 19

john.uhden
Mentor
Mentor
You lost me there, but I hope you're having fun.
Might the range be "where the deer and the antelopes play?"

John F. Uhden

0 Likes
Message 13 of 19

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:
....
Might the range be "where the deer and the antelopes play?"

[ If we're going to get into corny jokes, I did notice that ' ... it shows all the angels in "E" ', and wondered how the size of "E" compares to the head of a pin. ]

Kent Cooper, AIA
0 Likes
Message 14 of 19

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:
....
Should the 'degt' variable be calculated differently?  ....

Or, if the calculation of that remains, it's just the proportion that 'angt' is of a full circle, so the tests in the (cond) function should be different:

....
  degt (/ angt (* 2 pi))

  side

    (cond

      ((<= degt (/ 1 32.0)) "E")

      ((<= degt (/ 3 32.0)) "ENE")

      ((<= degt (/ 5 32.0)) "NE")

      ((<= degt (/ 7 32.0)) "NNE")

      ((<= degt (/ 9 32.0)) "N")

      ((<= degt (/ 11 32.0)) "NNW")

      ((<= degt (/ 13 32.0)) "NW")

      ((<= degt (/ 15 32.0)) "WNW")

      ((<= degt (/ 17 32.0)) "W")

      ((<= degt (/ 19 32.0)) "WSW")

      ((<= degt (/ 21 32.0)) "SW")

      ((<= degt (/ 23 32.0)) "SSW")

      ((<= degt (/ 25 32.0)) "S")

      ((<= degt (/ 27 32.0)) "SSE")

      ((<= degt (/ 29 32.0)) "SE")

      ((<= degt (/ 31 32.0)) "ESE")

      ("E")

    ); cond

  ); setq
....

[You can substitute the decimal equivalents of all those fractions, if you prefer.]

 

Or, 'degt' could be defined as the number of thirty-seconds 'angt' is of a full circle, greatly simplifying the (cond) tests:

....
  degt (* (/ angt (* 2 pi)) 32)

  side

    (cond

      ((<= degt 1) "E")

      ((<= degt 3) "ENE")

      ((<= degt 5) "NE")

      ((<= degt 7) "NNE")

      ((<= degt 9) "N")

      ((<= degt 11) "NNW")

      ((<= degt 13) "NW")

      ((<= degt 15) "WNW")

      ((<= degt 17) "W")

      ((<= degt 19) "WSW")

      ((<= degt 21) "SW")

      ((<= degt 23) "SSW")

      ((<= degt 25) "S")

      ((<= degt 27) "SSE")

      ((<= degt 29) "SE")

      ((<= degt 31) "ESE")

      ("E")

    ); cond

  ); setq
.... 

Kent Cooper, AIA
Message 15 of 19

john.uhden
Mentor
Mentor
I believe that's 22.5°

John F. Uhden

0 Likes
Message 16 of 19

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

hello 

so good thank you 👍

but it shows all the angels in "E"

I think we have to describe a range for that ?


Yes, as noted by other folks, the formula for the degt is wrong.

But more importantly, I'll try to explain why cond expression is enough as it is. It very popular function, lots of people prefers cond over if.

 

Here's what the HELP says:

(cond [((test) (result ...)) ...])

 

For more tests is evaluated this way:

 

(cond ((test1)		; if test1 is T (TRUE is anything BUT nil)
       (result1))	; then return the value of result1 and quit cond 
      			; else go to the following test
      ((test2)   	; if test2 is T 
       (result2))	; then return the value of  result2 and quit cond 
			; else go to the following test
      ((test3)   	; if test3 is T 
       (result3))	; then return the value of  result2 and quit cond 
      )			; .... else return nil.


(cond ((test1))		; if test1 (the value of it) is T 
			; then (test1 /= nil) as there is no result1 is returned the value of test1 itself (the actual value not just T)
      			; else (test1 = nil) keep going to the following test
      ((test2)		; if test2 is T 
       (result2))	; then return the value of  result2 and quit cond 
      			; else go to the following test
      (T		; if test3 is T (which always is)
       (result3)))	; then return the value of result3 and quit cond 


(setq side (cond ((<= degt 11.25) "E")		; if degt is <= 11.25 return "E" and stop, else next
		 ((<= degt 33.75) "ENE")	; if degt is <= 33.75 (remember if dewt <= 11.25 already taken and process left the cond from evaluation!) return "ENE" and stop, else next
		 ((<= degt 56.25) "NE")		; if degt is <= 56.25 (remember dewt <= 11.25 and degt <= 33.75 already taken!) return "NE" and stop, else next
		 ...
		 ((<= degt 348.75) "ESE")	; if degt is <= 348.75 return ESE" and stop, else next
		 ("E")))			; now all degt <= 348.75 were taken, now return "E" (as "E"=T) for anything above and stop.


;; Think of these

(setq *wa-angs* (cond ((getangle "\nSite angle <0>: "))
		      (0)))

(setq *wa-hig* (cond ((initget (+ 2 4)))
		     ((getdist (strcat "\nWall height <" (rtos *wa-hig*) ">: ")))
		     (*wa-hig*)))

The cond function returns the actual values of a test function.

 

Unlike or, and, =, eq... they return just T/nil:

  (or *wa-hig*
	(setq *wa-hig* 0))

 

Compare to the other two expressions:

(setq *wa-hig* (or *wa-hig*
		   0))

(setq *wa-hig* (cond (*wa-hig*)
		     (0)))

Why the first one can't be used, while the latter can.

HTH

Message 17 of 19

Anonymous
Not applicable

thank you🙏

0 Likes
Message 18 of 19

Anonymous
Not applicable

thank you it works 👍

I change with above formulas and it works.

but i couldn't use the:

degt (* (/ angt (* 2 pi)) 32)

  side

    (cond

      ((<= degt 1) "E") , ...

 

but thank you all for your cooperation 🙏

 

 

0 Likes
Message 19 of 19

Anonymous
Not applicable

thank you 🙏

0 Likes