Author Topic: using COND  (Read 2908 times)

0 Members and 1 Guest are viewing this topic.

Zahex

  • Guest
using COND
« on: May 15, 2005, 06:20:02 PM »
Hey everybody!

I'm having a problem with my code because of the cond's.
I want that in the change question leads me to drawing the spiral but i can't do it...

What should i do?

Code: [Select]

(alert "To run type: Tatlin")



(defun c:spiral0 ()
  (command "layer" "new" "spiral0" "color" "53" "spiral0" "")
  (c:despiral)
  ) ; end defun



(defun c:despiral(param)()

(setq selec (entsel "Click in the solid where you want to draw the spiral:"))
 
  (setq spin -1); -1=CW, 1=CCW
  (setq ri (car param) rf (cadr param))
  (setq h (nth 2 param))
  (initget (+ 1 2 4))
  (setq ns (getint "number of spirals:" ))
  (setq tu (getreal "Number of turns: "))
  (setq rt (getreal "extrusion radius: "))
  (setq segs (nth 3 param))
  (setq old (getvar "osmode"))
  (setvar "cmdecho" 0)  
  (setq fi1 (/ (* 2 PI) segs) i 0)
  (setq points (fix (* tu segs))
h1     (/ h points)
r1     (/ (- rf ri) points)
s      (last param)
  ) ;end setq
 
  (setvar "osmode" 0 )
  (command "3dpoly")
  (setq i 0)
  (repeat (1+ points)
    (setq fi (* i fi1) h (* i h1) r (+ ri (* i r1)))
    (setq x (* r (cos fi)) y (* spin r (sin fi)))
    (command (list (+ (car s) x) (+ (cadr s) y) (+ (caddr s) h)))
    (setq i (1+ i)))
  (command "")
  (setvar "osmode" old)
  (setq spiral (entlast))
  (command "ucs" "n" "za" (polar s 0 ri)
  (list
  (+(car s) (* ri (cos fi1)))
  (+(cadr s) (* spin ri (sin fi1)))h1))


  (command "circle" "0,0,0" rt)
  (command "extrude" (entlast) "" "p" spiral)
  (setvar "osmode" old)
  (command "ucs" "p")
  (command "array" (entlast) "" "p" s ns 360 "y")
 

  (c:spiral0)
  ) ; end defun despiral





;;; Transformation question

(defun c:Question ()
  (command "zoom" "e")
 
  (setq answer (getstring "\n (c)hange ,e(x)it ou (r)estart?: "))
  (while (and (/= answer "c")
     (/= answer "x")
     (/= answer "r")
) ; and
    (setq answer (getstring
"Only c,x ou r!: "
      ) ; getstring
    ) ; setq
  ) ;while
  (cond
    ((= answer "c")(c:spiral))
    ((= answer "x"))
    ((= answer "r")(c:restart))
    )
  ); defun
   



(defun c:solid ()
  (setq r1 (getdist "\n larger radius: ")
r2 (getdist "\n smaller radius: ")
h (getdist "\n height: ")
sides (getint "\n number of polygon sides: ")          
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)
  (list r1 r2 h sides centerpt)
  (command "zoom" "ex")
 (c:Question)
) ;end defun solid



 
  ;;; initial function

(defun c:Tatlin ()
  (c:solid)
) ;defun




Thanks

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
using COND
« Reply #1 on: May 15, 2005, 07:46:41 PM »
Something like this:
Code: [Select]
(defun c:Question ()
  (command "zoom" "e")
  (initget 1 "Change eXit Restart")
  (setq answer (getkword "\n Enter option: [Change/eXit/Restart] "))
  (cond
    ((eq answer "Change")(c:spiral))
    ((eq answer "eXit"))
    ((eq answer "Restart")(c:restart))
    )
  (princ)
  ); defun
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Zahex

  • Guest
there's something wrong with change option
« Reply #2 on: May 15, 2005, 07:54:40 PM »
there's something wrong with change option:

Quote

 insertion point:
 Enter option: [Change/eXit/Restart] c
; error: too few arguments
Command: 'VLIDE
Command:


Why does this happens?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
using COND
« Reply #3 on: May 15, 2005, 08:05:42 PM »
Well you need to debug your code.
the function: (defun c:despiral(param)()
is looking for a value passed to the routine, in this case the param.
If you know the value of the param you need to pass it but the function must be
(defun despiral(param) not (defun c:despiral(param) to accept a value passed.
and the new call will be
Code: [Select]
(defun c:spiral0 ()
  (command "layer" "new" "spiral0" "color" "53" "spiral0" "")
  (setq param <to the value you want to use>)
  (despiral param)
  ) ; end defun

 
  Did you follow that explanation?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
using COND
« Reply #4 on: May 16, 2005, 09:49:53 AM »
What I would do...
Code: [Select]
(alert "To run type: Tatlin")

(defun spiral0 (Pnt)
 (command "_.layer" "_new" "spiral0" "_color" "53" "spiral0" "")
 (despiral Pnt)
 T
) ; end defun

(defun despiral (Pnt / spin ns tu rt old fi1 i points h h1 r1 fi r x y spiral)
;;; (setq selec (entsel "Click in the solid where you want to draw the spiral:")) ;????
 (setq spin -1); -1=CW, 1=CCW
 (cond
  ((and
    (not (initget (+ 2 4)))
    (not (setq ns (getint "\n Number of spirals <exit>:" )))
   )
   nil
  )
  ((and
    (not (initget (+ 2 4)))
    (not (setq tu (getreal "\n Number of turns <exit>: ")))
   )
   nil
  )
  ((and
    (not (initget (+ 2 4)))
    (not (setq rt (getreal "\n Extrusion radius <exit>: ")))
   )
   nil
  )
  (T
   (setq old (getvar "osmode"))
   (setvar "cmdecho" 0)
   (setq fi1    (/ (* 2 pi) Me:Sds)
         i      0
         points (fix (* tu Me:Sds))
         h1     (/ Me:Hgt points)
         r1     (/ (- Me:Srd Me:Lrd) points)
   )
   (setvar "osmode" 0 )
   (command "_.3dpoly")
   (repeat (1+ points)
    (setq fi (* i fi1)
          h  (* i h1)
          r  (+ Me:Lrd (* i r1))
          x  (* r (cos fi))
          y  (* spin r (sin fi))
          i  (1+ i)
    )
    (command (list (+ (car Pnt) x) (+ (cadr Pnt) y) (+ (caddr Pnt) h)))
   )
   (command "")
   (setq spiral (entlast))
   (command "_.ucs" "_n" "_za"
            (polar Pnt 0 Me:Lrd)
            (list
             (+ (car Pnt) (* Me:Lrd (cos fi1)))
             (+ (cadr Pnt) (* spin Me:Lrd (sin fi1)))
             h1
            )
            "_.circle" '(0 0 0) rt
            "_.extrude" (entlast) "" "_p" spiral
            "_.ucs" "_p"
            "_.array" (entlast) "" "_p" Pnt ns 360 "_y"
   )
   (setvar "osmode" old)
   T
  )
 )
) ; end defun despiral

;;; Transformation question
(defun Question (Pnt / Answer)
 (command "_.zoom" "_e")
 ;;;CAB's sample:
 (initget 1 "Change eXit Restart")
 (setq Answer (getkword "\n Enter option [Change/eXit/Restart]: "))
 (cond
  ((eq Answer "Change") (spiral0 Pnt)) ;<- There is no function with the name 'spiral'!!!
  ((eq Answer "eXit") T)
  ((eq Answer "Restart") nil)
 )
); end defun Question  

(defun c:Tatlin ( / CenPnt CurAng ExLoop OldOsm TmpPmt)
 (while (not ExLoop)
  (cond
   ((not (setq CenPnt (getpoint "\n Insertion point: ")))
    (setq ExLoop T)
   )
   ((and
     (not (initget (+ 2 4)))
     (setq TmpPmt (if Me:Lrd
                   (strcat "\n Larger radius <" (rtos Me:Lrd) ">: ")
                   "\n Larger radius: "
                  )
     )
     (not (setq Me:Lrd (cond ((getdist CenPnt TmpPmt)) (Me:Lrd))))
    )
    (setq ExLoop T)
   )
   ((and
     (not (initget (+ 2 4)))
     (setq TmpPmt (if Me:Srd
                   (strcat "\n Smaller radius <" (rtos Me:Srd) ">: ")
                   "\n Smaller radius: "
                  )
     )
     (not (setq Me:Srd (cond ((getdist CenPnt TmpPmt)) (Me:Srd))))
    )
    (setq ExLoop T)
   )
   ((and
     (not (initget (+ 2 4)))
     (setq TmpPmt (if Me:Hgt
                   (strcat "\n Height: <" (rtos Me:Hgt) ">: ")
                   "\n Height: "
                  )
     )
     (not (setq Me:Hgt (cond ((getdist CenPnt TmpPmt)) (Me:Hgt))))
    )
    (setq ExLoop T)
   )
   ((and
     (not (initget (+ 2 4)))
     (setq TmpPmt (if Me:Sds
                   (strcat "\n Number of polygon sides: <" (itoa Me:Sds) ">: ")
                   "\n Number of polygon sides: "
                  )
     )
     (not (setq Me:Sds (cond ((getint TmpPmt)) (Me:Sds))))
    )
    (setq ExLoop T)
   )
   (T
    (setq OldOsm (getvar "osmode")
          CurAng (atan (* (/ (- Me:Lrd Me:Srd) Me:Hgt) (cos (/ pi Me:Sds))))
    )
    (setvar "osmode" 0)
    (command "_.polygon" Me:Sds CenPnt "_I" (polar CenPnt 0 Me:Lrd))
    (command "_.extrude" (entlast) "" Me:Hgt (/ (* CurAng 180.0) pi))
    (setvar "osmode" OldOsm)
    (command "_.zoom" "_ex")
    (setq ExLoop (Question CenPnt))
   )
  )
 )
 (princ)
) ;end defun Tatlin

Cheers
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

Zahex

  • Guest
using COND
« Reply #5 on: May 16, 2005, 10:36:17 AM »
Hey Jurg!

Thanks for replying...There's only one thing:instead of appearing,couldn't the spirals be drawn when http://clicking the solid previously drawn?

Thanks

Zahex

  • Guest
using COND
« Reply #6 on: May 16, 2005, 10:38:54 AM »
Hi CAB:

Sorry not saying anything yesterday but right after i received your message my internet fell and i couldn't get in untill now..

Actually i didn't understood your explanation,could you try to explain it to me once more,please?

Thanks

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
using COND
« Reply #7 on: May 17, 2005, 02:44:07 AM »
Hi

Quote from: Zahex
(...)There's only one thing:instead of appearing,couldn't the spirals be drawn when http://clicking the solid previously drawn?


AFAIK, you've no direct access to the solid geometrie...

Cheers
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18