BKT Posted November 14, 2015 Share Posted November 14, 2015 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) ) Quote Link to comment Share on other sites More sharing options...
satishrajdev Posted November 14, 2015 Share Posted November 14, 2015 Have a look on this thread... Lee sir has explained it really well http://www.cadtutor.net/forum/showthread.php?94089-Exit-while-loop-right-click. Quote Link to comment Share on other sites More sharing options...
BKT Posted November 14, 2015 Author Share Posted November 14, 2015 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) ) Quote Link to comment Share on other sites More sharing options...
satishrajdev Posted November 16, 2015 Share Posted November 16, 2015 (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) ) Quote Link to comment Share on other sites More sharing options...
BKT Posted November 16, 2015 Author Share Posted November 16, 2015 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 Quote Link to comment Share on other sites More sharing options...
satishrajdev Posted November 17, 2015 Share Posted November 17, 2015 You're welcome :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.