CivilTechSource Posted Sunday at 12:57 PM Posted Sunday at 12:57 PM Hi again, Looking to create a lisp that will bring a block into a drawing and will loop and keep adding it. The catch is that I want to see the visual of the block similar to the -insert command. So I managed to achieve the visual by adding the pause. But how do I make the while loop keep going without the getpoint? Is there a way I could check for pause? Thanks again (while (setq ins (getpoint "\nSpecify point for block (ENTER to exit): ")) (command "-INSERT" GV-Block pause "" "" "0") ) Quote
CivilTechSource Posted Sunday at 01:03 PM Author Posted Sunday at 01:03 PM I think I solved it. Is this the most optimal way? (while continue (command "-INSERT" GV-Block pause "" "" "0") (if (= (getvar "CMDSTAT") 0) (setq continue nil) ) ) Quote
devitg Posted Sunday at 02:29 PM Posted Sunday at 02:29 PM 1 hour ago, CivilTechSource said: I think I solved it. Is this the most optimal way? (while continue (command "-INSERT" GV-Block pause "" "" "0") (if (= (getvar "CMDSTAT") 0) (setq continue nil) ) ) @CivilTechSource Quote Command: CMDSTAT Unknown command "CMDSTAT". Press F1 for help. Quote
Steven P Posted Sunday at 03:37 PM Posted Sunday at 03:37 PM (edited) If it is just a stand alone action, this will work but you have to escape out of it to cancel - you cannot have more to the routine, so stand alone only (while (= (command "-INSERT" GV-Block pause "" "" "0") nil) ) or this (while (setq pt1 (getpoint "Press LH Mouse to repeat, Enter / Space cancel")) (= (command "-insert" "circuitBreaker" pause 1 1 0) nil) ) Edited Sunday at 04:13 PM by Steven P 1 Quote
Lee Mac Posted Monday at 07:45 AM Posted Monday at 07:45 AM Depending on your version of CAD, you can use this: (defun c:test ( ) (command "_.-insert" "yourblockname" "_s" 1 "_r" 0 "_re" "_y") (while (= 1 (logand 1 (getvar 'cmdactive))) (command "\\")) (princ) ) 1 1 Quote
CivilTechSource Posted Tuesday at 12:23 PM Author Posted Tuesday at 12:23 PM So the first line keeps doing the loop while it is not nil? How will it know it is not nil? On 19/10/2025 at 16:37, Steven P said: If it is just a stand alone action, this will work but you have to escape out of it to cancel - you cannot have more to the routine, so stand alone only (while (= (command "-INSERT" GV-Block pause "" "" "0") nil) ) or this (while (setq pt1 (getpoint "Press LH Mouse to repeat, Enter / Space cancel")) (= (command "-insert" "circuitBreaker" pause 1 1 0) nil) ) Quote
CivilTechSource Posted Tuesday at 12:25 PM Author Posted Tuesday at 12:25 PM I am still new with Lisp, but it feels that this is more elegant by checking if a command is active? On 20/10/2025 at 08:45, Lee Mac said: Depending on your version of CAD, you can use this: (defun c:test ( ) (command "_.-insert" "yourblockname" "_s" 1 "_r" 0 "_re" "_y") (while (= 1 (logand 1 (getvar 'cmdactive))) (command "\\")) (princ) ) Quote
Lee Mac Posted Tuesday at 12:39 PM Posted Tuesday at 12:39 PM 16 minutes ago, CivilTechSource said: So the first line keeps doing the loop while it is not nil? How will it know it is not nil? It won't - it will continue indefinitely until the user presses Esc to force it to exit. 1 Quote
Lee Mac Posted Tuesday at 12:40 PM Posted Tuesday at 12:40 PM 14 minutes ago, CivilTechSource said: I am still new with Lisp, but it feels that this is more elegant by checking if a command is active? If you need more information, check the documentation on the CMDACTIVE system variable. 1 Quote
Steven P Posted Tuesday at 01:24 PM Posted Tuesday at 01:24 PM 59 minutes ago, CivilTechSource said: So the first line keeps doing the loop while it is not nil? How will it know it is not nil? As Lee says, it doesn't know, it is a bit of a blunt LISP that does the job and no more. Lees is much better but I had a mental block yesterday, couldn't remember cmdactive. Quote
Lee Mac Posted Tuesday at 05:11 PM Posted Tuesday at 05:11 PM For completeness, the key here is the "Repeat" option of the -INSERT command - though, I'm unsure in which version this relatively new keyword was introduced. 1 Quote
ScottMC Posted 7 hours ago Posted 7 hours ago (edited) Thanks Lee.. you continue to inspire many. (defun c:mbi ( / *error* nobi p) (princ "\n Multi-Insert Block w.Total <!pp> ..") (defun *error* ( msg ) (setvar 'cmdecho 0) ;; 5.28.24 (vla-endundomark (vla-get-activedocument (vlax-get-acad-object))) (if msg (prompt (strcat "\n" msg))) (setvar 'cmdecho 1) (princ) ) (defun ccv ( / p) (setq p (getvar 'lastpoint)) (princ (setq pp ;; make/prints coords & paste usable (strcat " | " (rtos (car p) 2 4) "," ;; 'p' -- vertex from getpoint,... (rtos (cadr p) 2 4) "," (rtos (caddr p) 2 4) ) ) ) ) (command "DDINSERT" "\\") (setvar 'cmdecho 0) (setq nobi 1) (princ (strcat "\n Tot: " (rtos nobi))) (ccv) ;; coords (while T ;; insert loop of selected block (setq nobi (1+ nobi)) (princ (strcat "\n Tot: " (rtos nobi))) (command "_.-INSERT" "" "_s" 1 "_r" 0 "\\") ;; "_y") ; (ccv) ;; coords ) (*error* nil) (princ) ) Edited 6 hours ago by ScottMC first file attach.. rather it be as theswamp [code][/code] Quote
mhupp Posted 5 hours ago Posted 5 hours ago looks like your command outputs like Tot: 1 | x, y, z Tot: 2 | x, y, z Tot: 3 | x, y, z Another option if you just using that output for checking use the status line with modemacro tho it would only be the last count / point info ;;----------------------------------------------------------------------------;; ;; Insert Block with Tot: Count and X, Y, Z output into status bar (defun c:mbi ( / *error* nobi p doc) (vl-load-com) (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object)))) (princ "\n Multi-Insert Block w.Total <!pp> ..") (command "DDINSERT" "\\") (setvar 'cmdecho 0) (setq nobi 1) (ccv nobi) (while T ;; insert loop of selected block (command "_.-INSERT" "" "_s" 1 "_r" 0 "\\") ;; "_y") ; (setq nobi (+1 nobi) (ccv nobi) ;passes nobi to ccv as i ) (vla-endundomark doc) (setvar 'MODEMACRO "") (setvar 'cmdecho 1) (princ) ) (defun ccv (i / p str) (setq p (getvar 'lastpoint)) (setq str (strcat "Tot: " (rtos i) " | " (rtos (car p) 2 4) "," (rtos (cadr p) 2 4) "," (rtos (caddr p) 2 4))) (SETVAR 'MODEMACRO str) ) 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.