Kowal Posted October 6, 2015 Posted October 6, 2015 Hi, how exit the loop using the right mouse button. I know that the command returns nil but can not keep this knowledge to use. Please modifications of this simple example. (prompt "\nmbo") (defun c:mbo (/ ent pnt osm) (while (if (setq ent (entsel "\nSelect object: ")) (progn (if (= (cdr (assoc 0 (entget (car ent)))) "CIRCLE") (progn (if (= (cdr (assoc 62 (entget (car ent)))) 1) (progn (setq pnt (cdr (assoc 10 (entget (car ent))))) (setq osm (getvar "osmode")) (setvar "osmode" 0) (command "_move" ent "" pnt pause) (setvar "osmode" osm) );progn (princ "\n*** Wrong color circle ***") );if );progn (princ "\n*** This is not a circle ***") );if );progn (princ "\n*** Nothing selected ***") );if );while (princ) ) Quote
BIGAL Posted October 7, 2015 Posted October 7, 2015 (edited) Simple fix will work if you pick nothing as well. (defun c:mbo (/ ent pnt osm) (while (/= (setq ent (entsel "\nSelect object: ")) nil) (if (= (cdr (assoc 0 (entget (car ent)))) "CIRCLE") Edited October 7, 2015 by BIGAL Quote
satishrajdev Posted October 7, 2015 Posted October 7, 2015 Or (while (setq ent (entsel "\nSelect object: ")) (if ent (progn Quote
Tharwat Posted October 7, 2015 Posted October 7, 2015 There is no need for if function nor progn function since while function would behave like if function but continuously till it returns nil . eg. (while(setq ent (entsel "\nSelect object: ")) ;; do your stuff here ;; ) Quote
Lee Mac Posted October 7, 2015 Posted October 7, 2015 The following is my preferred technique - I find this approach cleaner and it also accounts for a missed pick: (defun c:mbo ( / ent enx ) (while (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect object: "))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ;; Stay in loop ) ( (null ent) nil ;; Exit loop ) ( (/= "CIRCLE" (cdr (assoc 0 (setq enx (entget ent))))) (princ "\nSelected object is not a circle.") ;; Stay in loop ) ( (/= 1 (cdr (assoc 62 enx))) (princ "\nSelected circle colour property not set to red.") ;; Stay in loop ) ( (command "_.move" ent "" "_non" (trans (cdr (assoc 10 enx)) ent 1) "\\")) ;; Exit loop ) ) ) (princ) ) Quote
David Bethel Posted October 7, 2015 Posted October 7, 2015 Lots of ways for this. I prefer ssget calls : [b][color=BLACK]([/color][/b]while [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget [b][color=GREEN]([/color][/b]list [b][color=BLUE]([/color][/b]cons 0 [color=#2f4f4f]"CIRCLE"[/color][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]cons 62 1[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]cons 210 [b][color=RED]([/color][/b]trans '[b][color=PURPLE]([/color][/b]0 0 1[b][color=PURPLE])[/color][/b] 1 0[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]= [b][color=MAROON]([/color][/b]sslength ss[b][color=MAROON])[/color][/b] 1[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq en [b][color=MAROON]([/color][/b]ssname ss 0[b][color=MAROON])[/color][/b] ed [b][color=MAROON]([/color][/b]entget en[b][color=MAROON])[/color][/b] ce [b][color=MAROON]([/color][/b]cdr [b][color=GREEN]([/color][/b]assoc 10 ed[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]initget 1[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq p2 [b][color=NAVY]([/color][/b]getpoint ce [color=#2f4f4f]"\nNew Center Point: "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]command [color=#2f4f4f]"_.MOVE"[/color] en [color=#2f4f4f]""[/color] ce [color=#2f4f4f]"_non"[/color] p2[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]redraw[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] -David Quote
Kowal Posted October 7, 2015 Author Posted October 7, 2015 Thanks. Lee your version is perfect. If you can not exit the loop when you select the red circle. (defun c:mbo ( / ent enx ) (while (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect object: "))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ;; Stay in loop ) ( (null ent) nil ;; Exit loop ) ( (/= "CIRCLE" (cdr (assoc 0 (setq enx (entget ent))))) (princ "\nSelected object is not a circle.") ;; Stay in loop ) ( (/= 1 (cdr (assoc 62 enx))) (princ "\nSelected circle colour property not set to red.") ;; Stay in loop ) ( (command "_.move" ent "" "_non" (trans (cdr (assoc 10 enx)) ent 1) "\\")) ;; [color="red"]Exit loop -> Stay in loop[/color] ) ) ) (princ) ) Quote
Lee Mac Posted October 7, 2015 Posted October 7, 2015 You're welcome Kowal - to stay in the loop (and perform other commands), you could use the following: (defun c:mbo ( / ent enx ) (while (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect object: "))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ;; Stay in loop ) ( (null ent) nil ;; Exit loop ) ( (/= "CIRCLE" (cdr (assoc 0 (setq enx (entget ent))))) (princ "\nSelected object is not a circle.") ;; Stay in loop ) ( (/= 1 (cdr (assoc 62 enx))) (princ "\nSelected circle colour property not set to red.") ;; Stay in loop ) ( t (command "_.move" ent "" "_non" (trans (cdr (assoc 10 enx)) ent 1) "\\") ;; < Additional operations > t ;; Stay in loop ) ) ) ) (princ) ) Quote
Kowal Posted October 8, 2015 Author Posted October 8, 2015 Great thanks to Lee, you're the best. Quote
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.