Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Stopping the while loop

2 REPLIES 2
Reply
Message 1 of 3
smaher12
398 Views, 2 Replies

Stopping the while loop

I am have trouble trying to figure a couple of things in the following code. Any advice??

 

First - in the IF statement if "SD" is >= ask "Specify LAST strata number". How do I add nil?

Second -  After I "Specify the LAST strata number", How do I stop the loop?

 

(defun C:22 ()
  (setvar 'osmode 0)
  
  (or $S (setq $S 10))
    (setq S (getdist (strcat "\nSpecify scale [Inches equal a Foot] <"(rtos $S 2 2)">: ")))
      (if (= S nil) (setq S $S))
        (setq $S S)

  (or $BD (setq $BD 7))
    (setq BD (getdist (strcat "\nSpecify boring depth in feet <"(rtos $BD 2 2)">: ")))
      (if (= BD nil) (setq BD $BD))
        (setq $BD BD)

  (setq P1 (getpoint "\nSpecify starting point: ")
	P2 (list (+ 1.5 (car P1)) (cadr P1))
	P3 (list (car P2) (- (cadr P2)(* BD S)))
	P4 (list (- (car P3) 3) (cadr P3))
	P5 (list (car P4) (cadr P2))
  )
  (command "pline" P2 P3 P4 P5 "C")

  (while
    (setq SD (getdist "\nSpecify strata depth: ")
	  SD1 (list (car P5) (- (cadr P5) (* SD S)))
	  SD2 (list (+ 3 (car SD1)) (cadr SD1))
    )
 
 (if (>= SD BD)
   (progn
     (setq SN (getint "\nSpecify LAST strata number: ")
	   SN1 (list (car P2) (- (cadr P2) (/ (distance P2 P3) 2)))
	   )
     (command "text" "m" SN1 1.0 "0" SN)
   )
 )
     (setq SN (getint "\nSpecify strata number: ")
	   SN1 (list (car P2) (- (cadr P2) (/ (distance P2 SD2) 2)))
	   )
     (command "line" SD1 SD2 "")	    
     (command "text" "m" SN1 1.0 "0" SN)
     (setq P2 SD2)
  )
 (princ)
)

 

 

 

 

 

2 REPLIES 2
Message 2 of 3
stevor
in reply to: smaher12

 

1. 'add nil' does not compute, as you discovered. One way around:

test the variable for a nil content, and if nit set it to the number 0, ie,

 (if (not SD) (seta SD 0)) ; handle a nil entry; and inside the setq:

    (setq SD (getdist "\nSpecify strata depth: ")

              SD (if SD SD 0) .... etc

 

2. 'stop the loop' of a while could be, in your case, either:

 A. Add an user input in the while argument of ' (While (Setq ..

 like :   (while (and (/= "Y" (strcase (getstring "\n Exit, Y or N")))
             (setq SD (getdist "\nSpecify strata depth: ")
                   SD (if SD SD 0)
                   SD1 (list (car P5) (- (cadr P5) (* SD S)))
                   SD2 (list (+ 3 (car SD1)) (cadr SD1)) )
        ) ; and

 

                      

S
Message 3 of 3
smaher12
in reply to: stevor

Thank you. I see now. I just realized that I had one of the answers already in the top of program.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost