stlo Posted August 10, 2022 Posted August 10, 2022 (edited) Hi! I would like to create a defined sequence of commands for a new collegue but not with a recorded macro because I don't like the user input feature in those, it's messy (Maybe I'm missing something). If I write a simple routine with back to back commands, am I able at some point to create a loop that would say as an example "REPEAT" the align command "UNTIL" you hit the "Q" key and it would go automatically to next command so if I have 2 align to perform or 100 the code would loop until I hit the "Q" key without escaping the whole sequence! What I see for the user is that there wouldn't be any command typing, it would all be done automatically, the user would only have to perform the asking predefined commands and exiting some loops by pressing keys! Thanks for your time! Have a good day! Edited August 10, 2022 by stlo Mistype Quote
Jonathan Handojo Posted August 10, 2022 Posted August 10, 2022 Assuming that they're all AutoCAD commands and not LISP commands, perhaps you want something like this? (As soon as you hit escape, it's over) (defun c:foo ( / cmds rep) (setq cmds '("MOVE" "COPY" "ALIGN")) ;; Your list of commands to rinse and repeat. Will repeat to the start at the end of the list (while (progn (command (car cmds)) (while (not (zerop (getvar "cmdactive"))) (command pause)) (initget "Repeat Next Exit") (setq rep (getkword (strcat "\nRepeat " (car cmds) " command or proceed to next? [Repeat/Next/Exit]: <Repeat>: "))) (cond ((member rep '("Repeat" nil))) ((= rep "Next") (setq cmds (append (cdr cmds) (list (car cmds))))) ) ) ) (princ) ) 1 Quote
stlo Posted August 10, 2022 Author Posted August 10, 2022 Hi Jonathan! Thanks a lot! What if I have lisp commands also? Can I just add those to the list? Quote
Jonathan Handojo Posted August 11, 2022 Posted August 11, 2022 (edited) LISP commands are called differently, so it wouldn't simply work if you put "YOURLISP" or "C:YOURLISP" to the above. Because they are user-defined functions, you would have to call them like you would any other sub functions. The routine can of course be modified to suit. In my case below, for a LISP command, do not put them in quotations in the list, and supply the full name of your function including the "c:" (defun c:foo ( / cmd cmds rep) (setq cmds '("MOVE" "COPY" c:lisp1 c:lisp2 "ALIGN")) ;; Your list of commands to rinse and repeat. Will repeat to the start at the end of the list (while (progn (cond ( (eq (type (setq cmd (car cmds))) 'str) (command cmd) (while (not (zerop (getvar "cmdactive"))) (command pause)) ) ( (and (eq (type cmd) 'sym) (member (type (eval cmd)) '(subr usubr))) ((eval cmd)) ) ) (initget "Repeat Next Exit") (setq rep (getkword (strcat "\nRepeat " (if (eq (type cmd) 'sym) (vl-string-subst "" "C:" (vl-prin1-to-string cmd)) cmd) " command or proceed to next? [Repeat/Next/Exit]: <Repeat>: ") ) ) (cond ((member rep '("Repeat" nil))) ((= rep "Next") (setq cmds (append (cdr cmds) (list cmd)))) ) ) ) (princ) ) Edited August 11, 2022 by Jonathan Handojo 1 Quote
BIGAL Posted August 11, 2022 Posted August 11, 2022 One of the simplest is did you pick an object if no then exit (while (setq ent (entsel "\nPick object - Press Enter to exit")) do your stuff ) ; while 1 Quote
stlo Posted August 11, 2022 Author Posted August 11, 2022 Thanks for your help guys!!! BIGAL, I will try this in a routine for sure! Jonathan, this is exactly what I was looking for! I love this stuff! I will have a lot of fun trying to build the perfect sequence! Simply Wow! Have a great evening guys! 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.