I am trying to put together a loop to enter a number greater than the previous number entered. Below is my mockup and I just cannot get it.
(defun c:22 () (while (setq d (getreal "\nSpecify diameter: ")) (setq $d d) (while (if (<= d $d) (progn (prompt "\nSpecify greater diameter.") (setq d (getreal "\nSpecify diameter: ")) ) ) ) (setq p1 (getpoint "\nSpecify point: ")) (command "CIRCLE" p1 d) ) )
Solved! Go to Solution.
Solved by Lee_Mac. Go to Solution.
@smaher12 wrote:
I am trying to put together a loop to enter a number greater than the previous number entered. Below is my mockup and I just cannot get it.
Try
(defun c:22 ( / $D D P1) (if (and (setq d (getreal "\nSpecify diameter: ")) (setq $d d) ) (while (> d $d) (setq p1 (getpoint "\nSpecify point: ")) (command "CIRCLE" p1 d) (setq $d d) (prompt "\nSpecify greater diameter.") (setq d (getreal "\nSpecify diameter: ")) ) ) (princ) )
Henrique
Perhaps something along these lines:
(defun c:22 ( / $d d p1 ) (while (progn (initget 6) (setq d (getdist "\nSpecify diameter <exit>: ")) ) (if (and (= 'real (type $d)) (<= d $d)) (prompt (strcat "\nDiameter must be greater than " (rtos $d))) (if (setq p1 (getpoint "\nSpecify center <back>: ")) (progn (command "_.circle" "_non" p1 d) (setq $d d) ) ) ) ) (princ) )
Alternatively:
(defun c:22 ( / $d d p1 ) (while (progn (initget 6) (setq d (getdist "\nSpecify diameter <exit>: ")) (cond ( (null d) nil) ( (and (= 'real (type $d)) (<= d $d)) (princ (strcat "\nDiameter must be greater than " (rtos $d))) ) ( (setq p1 (getpoint "\nSpecify center <exit>: ")) (command "_.circle" "_non" p1 d) (setq $d d) ) ) ) ) (princ) )
Many thanks Lee. Well, I applied the mock up to my model and it opened another can of worms.
I am trying to add a cond if the strata depth is greater than the boring depth (princ Strata depth is greater than boring depth.
Also, when I exit Strata depth I still need to select a hatch pattern and hatch the remaining section.
(defun c:22 () (or $sc (setq $sc 60)) (setq sc (getreal (strcat "\nSpecify scale [Inches = Foot] <"(rtos $sc 2 1)">: "))) (if (not sc) (setq sc $sc)) (setq $sc sc) (or $bd (setq $bd 7)) (setq bd (getreal (strcat "\nSpecify boring depth in feet <"(rtos $bd 2 1)">: "))) (if (not bd) (setq bd $bd)) (setq $bd bd) (setq p0 (getpoint "\nSpecify starting point: ") p1 (list (- (car p0) 9) (cadr p0)) p2 (list (+ 9 (car p0)) (cadr p0)) p3 (list (car p2) (- (cadr p2)(* bd sc))) p4 (list (car p1) (cadr p3))) (command "pline" p1 p2 p3 p4 "C") (setq p9 p1) (setq P10 p4) (setq $d 0) (while (progn (initget 6) (setq d (getdist "\nSpecify strata depth <exit>: ")) (cond ( (null d) nil) ( (and (= 'real (type $d)) (<= d $d)) (princ (strcat "\nDepth must be greater than " (rtos $d))) ) ( (setq pn (getstring (strcat "\nSpecify pattern name <" (getvar "hpname") ">: "))) (if pn (= nil) (setq pn (getvar "hpname"))) (setq d1 (list (car p9) (- (cadr p9) (* d sc)))) (setq d2 (list (+ 18 (car d1)) (cadr d1))) (command "line" d1 d2 "") (command "hatch" "p" pn "80" "w" "" "" d1 d2 p2 p1 "c" "") (setq $d d) ) ) ) ) (princ) )
smaher12 wrote:I am trying to add a cond if the strata depth is greater than the boring depth (princ Strata depth is greater than boring depth.
And exactly what is the problem? Are you getting an error message when you attempt it? What is the error? What is not working right (or makes you think it's not working right)? Is there any portion that DOES work? What?
Don Ireland
Engineering Design Technician
Okay, the following code does what I need it to. I was just hoping someone can take a look at it and see if the condition section can be a little more efficient. Any suggestions are helpful. Thanks.
(defun c:22 () (or $scale (setq $scale 60)) (setq scale (getreal (strcat "\nSpecify scale <"(rtos $scale 2 1)">: "))) (if (not scale) (setq scale $scale)) (setq $scale scale) (or $depth (setq $depth 4)) (setq depth (getreal (strcat "\nSpecify depth in feet <"(rtos $depth 2 1)">: "))) (if (not depth) (setq depth $depth)) (setq $depth depth) (setq p0 (getpoint "\nSpecify starting point: ") p1 (list (- (car p0) 9) (cadr p0)) p2 (list (+ 9 (car p0)) (cadr p0)) p3 (list (car p2) (- (cadr p2)(* depth scale))) p4 (list (car p1) (cadr p3)) p5 (list (- (car p0) 9) (cadr p0)) ) (setvar 'osmode 0) (command "pline" p2 p3 p4 p1 "C") (setq $sdepth 0) (while (progn (initget 6) (setq sdepth (getdist "\nSpecify strata depth <exit>: ")) (cond ((and (not sdepth))(wrapup) ) ((and (= 'real (type sdepth)) (= sdepth depth)) (wrapup) ) ((and (= 'real (type sdepth)) (> sdepth depth)) (princ (strcat "\nStrata depth must be less than boring depth " (rtos depth 2 1))) ) ((and (= 'real (type $sdepth)) (<= sdepth $sdepth)) (princ (strcat "\nStrata depth must be greater than " (rtos $sdepth 2 1))) ) ((and (= 'real (type $sdepth)) (> sdepth depth)) (princ (strcat "\nStrata depth must be less than boring depth " (rtos depth 2 1))) ) ((and (= 'real (type $sdepth)) (= sdepth depth)) (wrapup) ) (; then do this (setq d1 (list (car p5) (- (cadr p5) (* sdepth scale))) d2 (list (+ 18 (car d1)) (cadr d1)) ) (command "line" d1 d2 "") (initget 1) (setq no (getint "\nSpecify strata number: ")) (command ; "-insert" "sn" (polar p2 (* pi 1.5) (/ (distance p2 d2) 2)) "" "" "" no "" "-HATCH" "P" "Ansi31" "80" "" "DR" "B" "W" "N" D1 D2 P2 P1 "C" "" "" ) (setq $sdepth sdepth) (setq p1 d1) (setq p2 d2) ); end then ); cond ); progn ); while (princ) ); 22 (defun wrapup () (initget 1) (setq no (getint "\nSpecify FINAL strata number: ")) (command ; "-insert" "sn" (polar p2 (* pi 1.5) (/ (distance p2 p3) 2)) "" "" "" no "" "-HATCH" "P" "Ansi33" "80" "" "DR" "B" "W" "N" P4 P3 P2 P1 "C" "" "" ) )
Can't find what you're looking for? Ask the community or share your knowledge.