Jump to content

A little trouble with calculating points in LISP


MarcoW

Recommended Posts

OK.

 

As I say, if AfraLISP doesn't help you, the Visual LISP Editor has got some indispensible help files that explain a great deal.

 

You can look up any function you are unsure of. :wink:

Link to comment
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    13

  • MarcoW

    10

  • David Bethel

    1

  • alanjt

    1

Top Posters In This Topic

Posted Images

Aarrgghh.. I'm making a mistake and I can't locate where that is. I tried hard but im too stu.. no, too novice :-)

 

Please look to the code below, when entering L for left side it works, when entering r or enter, it draws only 1 circle wicht doesn't come in the ss (with ssadd).

 

What am I doing wrong? I am convinced the parenthesis are good... but who am I...

 

Code:

 

 
(defun c:box1  (/ *error* vlst ovar ss len leng dist pt1 pt2 pt3 pt4 pt5 pt6)
 ; Error Handler
 (defun *error*  (msg)
   (if ovar
     (mapcar 'setvar vlst ovar)) ; If old variables are stored, reset them.
   (if (not (member msg '("Function cancelled" "quit / exit abort")))
 ; If the msg isn't one in this list
     (princ (strcat "\n<!> Error: " msg " <!>"))) ; then print it.
   (princ))
 (setq vlst '("CMDECHO" "OSMODE" "ORTHOMODE")
       ovar (mapcar 'getvar vlst)
       ss (ssadd)  ; Create an Empty Selection Set
 ; Define Functions and Localise Variables
       len (getdist "\nLength1:  ")
       leng (getdist "\nLength2:  ")
 ; I'd be more inclined to use "getdist"
 ; so that the user can pick the distance.
       dist (getdist "\nDistance:  ")
       dia (getreal "\nDiameter: ")
       pt1 (getpoint "\nInsertion:  ")
       pt2 (polar pt1 0 dist)

;;;                    pt1 +-----+
;;;                             pt2
       pt3 (polar pt2 (/ pi 2) (* len 0.5))

;;;                             pt3
;;;                              +
;;;                              |
;;;                              |
;;;                    pt1 +-----+
;;;                             pt2
       pt4 (polar pt3 0 leng)
;;;                             pt3   pt4
;;;                              +-----+
;;;                              |
;;;                              |
;;;                    pt1 +-----+
;;;                             pt2
       pt5 (polar pt4 (* pi 1.5) len)

;;;                             pt3   pt4
;;;                              +-----+
;;;                              |     |
;;;                              |     |
;;;                    pt1 +-----+     |
;;;                             pt2    |
;;;                                    |
;;;                                    +
;;;                                   pt5
       pt6 (polar pt5 pi leng)
;;;                             pt3   pt4
;;;                              +-----+
;;;                              |     |
;;;                              |     |
;;;                    pt1 +-----+     |
;;;                             pt2    |
;;;                                    |
;;;                              +-----+
;;;                             pt6   pt5
;; calculating points to right
     pt7  (polar pt3 0.0 (* 0.5 leng))
pt8 (polar pt7 (* pi 0.5) 100) ; 100 is distance between box and circle
  pt9 (polar pt8 (* pi 0.5) 60) ; 60 is distance between first and second circle
;; calculating points to left
    pt10 (polar pt6 0.0 (* 0.5 leng)) ;
      pt11 (polar pt10 (* pi 1.5) 100) ; 100 is distance between box and circle
 pt12 (polar pt11 (* pi 1.5) 60) ; 60 is distance between first and second circle
;;;
;;;         pt9 0
;;;         pt8 0  
;;;        pt3+-+-+ pt4
;;;    | 7 |
;;;    |   |
;;;                     +-------+   |
;;;   pt1 pt2 |
;;;    pt10|
;;;        pt6+-+-+pt5
;;;        pt11 0
;;;        pt12 0

    ) ; End Setq

 (mapcar 'setvar vlst '(0 0 1))  ; Set the Variables to how we want them
 (command "_.pline" pt3 pt4 pt5 pt6 pt3 pt5 "")  ; Make the Polyline
 ; Remember to use "_." prefix to make it
 ; compatible for all language versions.
 (ssadd (entlast) ss)  ; Add the polyline to the selection set
[color=red];; select side of wich the circle should appear[/color]
[color=red]   (initget "L R")[/color]
[color=red]   (setq side (getkword "\nCircle Left or Right? (L/R) <R>:  "))[/color]
[color=red];; only L or R can be given while <Enter> is same as R[/color]

[color=red](cond[/color]
[color=red]((= side "L")[/color]

[color=red];; when given L[/color]
[color=red];; ------------[/color]

[color=red]  (command "_.circle" pt11 "_D" dia)  ; Create the first Circle[/color]
[color=red]  (ssadd (entlast) ss)  ; Add the Circle to the selection set[/color]
[color=red]  (command "_.circle" pt12 "_D" dia)  ; Create the second Circle[/color]
[color=red]  (ssadd (entlast) ss))  ; Add the Circle to the selection set[/color]

[color=red];; when given R or <Enter> [/color]
[color=red];; ------------[/color]

[color=red]([/color]
[color=red] (command "_.circle" pt8 "_D" dia)  ; Create the first Circle[/color]
[color=red]  (ssadd (entlast) ss)  ; Add the Circle to the selection set[/color]
[color=red]  (command "_.circle" pt9 "_D" dia)  ; Create the second Circle[/color]
[color=red]  (ssadd (entlast) ss)  ; Add the Circle to the selection set[/color]
[color=red] )[/color]
[color=red])[/color]

(command "_.rotate" ss "" pt1 pause)
 (mapcar 'setvar vlst ovar) ; Reset System Variables
 (princ)
 ; Exit Cleanly
 ) ; End box1

Link to comment
Share on other sites

Just looking quickly, you have missed the "t" from your second COND statement:

 

([color=Blue][b]t[/b][/color]
    (command "_.circle" pt8 "_D" dia) ; Create the first Circle
    (ssadd (entlast) ss) ; Add the Circle to the selection set
    (command "_.circle" pt9 "_D" dia) ; Create the second Circle
    (ssadd (entlast) ss) ; Add the Circle to the selection set
    )
   )

Link to comment
Share on other sites

Lee, you are right... I checked the lisp file in wich i sniffed around and there is no " t " in it. Strange ...

 

Anyway, yes it works and again we are grateful !

Link to comment
Share on other sites

I'm not a lover of using loads of variables, but just as a variation, you could also write it like this:

 

(defun c:box1  (/ *error* vlst ovar ss len
                 leng dist pt1 pt2 pt3 pt4
                 pt5 pt6 pt7 pt8 pt9 pt10
                 pt11 pt12 tmp)

 (defun *error*  (msg)
   (if ovar (mapcar 'setvar vlst ovar))
   (if (not (member msg '("Function cancelled" "quit / exit abort")))
     (princ (strcat "\n<< Error: " msg " >>"))
     (princ "<<-- Cancelled -->>"))
   (princ))

 (or box:def (setq box:def "Right"))

 (setq vlst '("CMDECHO" "OSMODE" "ORTHOMODE")
       ovar (mapcar 'getvar vlst)
       ss   (ssadd)
       
       len  (getdist "\nLength1:  ")
       leng (getdist "\nLength2:  ")
       dist (getdist "\nDistance:  ")
       dia  (getreal "\nDiameter: ")
       pt1  (getpoint "\nInsertion:  ")
       
       pt2  (polar pt1 0 dist)
       pt3  (polar pt2 (/ pi 2) (* len 0.5))
       pt4  (polar pt3 0 leng)
       pt5  (polar pt4 (* pi 1.5) len)
       pt6  (polar pt5 pi leng)
       pt7  (polar pt3 0.0 (* 0.5 leng))
       pt8  (polar pt7 (* pi 0.5) 100)
       pt9  (polar pt8 (* pi 0.5) 60)
       pt10 (polar pt6 0.0 (* 0.5 leng)) 
       pt11 (polar pt10 (* pi 1.5) 100)
       pt12 (polar pt11 (* pi 1.5) 60))

 (mapcar 'setvar vlst '(0 0 1))
 (command "_.pline" pt3 pt4 pt5 pt6 pt3 pt5 "")
 (ssadd (entlast) ss)

 (initget "Left Right")
 (setq tmp (getkword (strcat "\nCircle Left or Right? (L/R) <" box:def ">: ")))
 (or (not tmp) (setq box:def (strcase tmp)))
 
 (if (= box:def "Right")
   (progn
    (command "_.circle" pt8 "_D" dia)
    (ssadd (entlast) ss)
    (command "_.circle" pt9 "_D" dia)
    (ssadd (entlast) ss))
   (progn      
    (command "_.circle" pt11 "_D" dia)
    (ssadd (entlast) ss)
    (command "_.circle" pt12 "_D" dia)
    (ssadd (entlast) ss)))

 (command "_.rotate" ss "" pt1 pause)
 (mapcar 'setvar vlst ovar)
 (princ))

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