Jump to content

Exiting A While Loop


BKT

Recommended Posts

I have a piece of code I'm playing with and I'm having a problem. I'm hoping someone here can take a look...

 

I wrote a loop to make a list of dimension values. I wanted to be able to handle missed selections, and that part seems to work fine, but I also wanted to have the selection stop with a right-mouse click. It works if I use REPEAT and the number of selections, but I really don't want to have to know ahead of time how many entities there are for selection. Is there some way to get this done? I've searched quite a lot, but can't seem to find the answer. I get the feeling I'm missing something simple.

 

Thanks for looking,

 

BKT

 

(defun c:test (/ a15 a42 bendr ent ent2 Gau kfac lst ss1)


(setq bendr 0.156)
(setq kfac 0.42)
(setq Gau 0.0598)

(setvar "cmdecho" 0)
(setvar "errno" 0)


(repeat 9
 (while
   (and
     (not (setq ent (entsel "\nSelect Dimension: ")))
     (= (getvar "errno") 7)
   )
   (princ "\nNothing Selected - Try Again!")
 )
(setq a42 (cdr (assoc 42 (entget (car ent)))))
(setq a15 (cdr (assoc 15 (entget (car ent)))))
(if (equal a15 '(0.0 0.0 0.0))(setq ent2 a42)(setq ent2 (* (- PI a42)(+ bendr (* kfac Gau)))))
(setq lst (append lst (list ent2)))
(princ ent2)
)

(terpri)
(princ lst)

(princ)

)

Link to comment
Share on other sites

Thanks, Satish!

 

I looked at that thread but was having trouble until I went back to it and realized I wasn't treating the COND properly. I've posted what I finally put together thanks to you, and of course, to Lee Mac. It works but if you see anything not quite right let me know, will you? I appreciate the help!

 

(defun c:test ( / a15 a42 bendr ent ent2 Gau kfac lst ss1)

(setq bendr 0.156)
(setq kfac 0.42)
(setq Gau 0.0598)

(setvar "cmdecho" 0)

   (while
       (progn
           (setvar 'errno 0)
           (setq ent (entsel "\nSelect Dimension: "))
           (cond
               ((= 7 (getvar 'errno))(princ "\nNothing Selected - try again."))
               ((null ent) nil)
               (t
                (progn
                   (setq a42 (cdr (assoc 42 (entget (car ent)))))
                   (setq a15 (cdr (assoc 15 (entget (car ent)))))
                   (if (equal a15 '(0.0 0.0 0.0))(setq ent2 a42)(setq ent2 (* (- PI a42)(+ bendr (* kfac Gau)))))
                   (setq lst (append lst (list ent2)))
                   (command "._chprop" ent "" "LA" "Xsec_dims" "C" "RED" "")
                )
                t
               )
           )
       )
   )
   (setq ss1 (ssget "_X" '((8 . "Xsec_dims"))))
   (command "._CHPROP" ss1 "" "LA" "Xsec_dims" "C" "ByLayer" "")
   (terpri)
   (princ lst)
   (princ)
)

Link to comment
Share on other sites

(defun c:test (/ a15 a42 bendr ent ent2 Gau kfac lst ss1)
 (setq	bendr 0.156
kfac  0.42
Gau   0.0598
 )
 (setvar "cmdecho" 0)

 (while
   (progn
     (setvar 'errno 0)
     (setq ent (entsel "\nSelect Dimension: "))
     (cond
((= 7 (getvar 'errno))
 (princ "\nNothing Selected - try again.")
)
((null ent) nil)
(t
 (setq a42 (cdr (assoc 42 (entget (car ent)))))
 (setq a15 (cdr (assoc 15 (entget (car ent)))))
 (if (equal a15 '(0.0 0.0 0.0))
   (setq ent2 a42)
   (setq ent2 (* (- PI a42) (+ bendr (* kfac Gau))))
 )
 (setq lst (append lst (list ent2)))
 (command "._chprop" ent "" "LA" "Xsec_dims" "C" "RED" "")
 t
)
     )
   )
 )
 (if (setq ss1 (ssget "_X" '((8 . "Xsec_dims"))))
   (command "._CHPROP"	ss1 "" "LA" "Xsec_dims"	"C" "ByLayer" "")
 )
 (terpri)
 (princ lst)
 (princ)
)

Link to comment
Share on other sites

I appreciate the help! When I get the rest of the program formatted properly it should be good to go. It already comes in very handy in the small shop where I'm working now to quickly create flat patterns for simple one direction sheet metal bends.

 

Thanks again,

BKT

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