samifox Posted April 10 Share Posted April 10 Hello everyone, I need to run a built-in command and decide what to do based on its output. For instance, keep trying the "Join" command until it shows "0 Joined." (defun c:JoinUntilZero () (while (/= (getvar 'cmdactive) 0) ; Check if a command is active (setq ss (ssget)) ; Prompt the user to select objects (if ss ; If a selection set is created (progn (command "_.JOIN" ss "") ; Execute the "Join" command (setq numJoined (getvar 'cmdresult)) (princ (strcat "\n" numJoined " objects joined.")) ; Display the result (if (= numJoined "0") ; Check if no objects were joined (progn (princ "\nAll objects joined. Exiting.") ; If so, exit the loop (setq ss nil) ; Clear the selection set to exit the loop ) ) ) (princ "\nNo objects selected. Exiting.") ; If no selection set, exit ) ) (princ) ) (c:JoinUntilZero) ; Call the function Quote Link to comment Share on other sites More sharing options...
mhupp Posted April 10 Share Posted April 10 (edited) I have this that repeats the command 3 times because one purge usually doesn't do it. ;;----------------------------------------------------------------------------;; ;; Purge 3 Times (defun C:PUALL () (repeat 3 (command "_.Purge" "A" "*" "N")) ) it might work with brute force? Edited April 10 by mhupp 1 Quote Link to comment Share on other sites More sharing options...
pkenewell Posted April 10 Share Posted April 10 @samifox There is no system variable called CMDRESULT that I know of in AutoCAD - so your code wont work in that respect. I don't know how else you would do this. Quote Link to comment Share on other sites More sharing options...
mhupp Posted April 10 Share Posted April 10 (edited) Maybe LASTPROMPT? -Edit Never mind that's the last thing the user inputted Edited April 10 by mhupp Quote Link to comment Share on other sites More sharing options...
pkenewell Posted April 10 Share Posted April 10 19 minutes ago, mhupp said: Maybe LASTPROMPT? -Edit Never mind that's the last thing the user inputted LOL - I thought about that too but it doesn't work. Quote Link to comment Share on other sites More sharing options...
pkenewell Posted April 10 Share Posted April 10 @samifox Honestly I don't understand why you would need this. The JOIN command itself will join multiple lines and Arc sequences together and outputs how many things it joined together into how many polylines. It's not like the old PEDIT command, where you had to "brute force" it as mhupp was saying. 1 Quote Link to comment Share on other sites More sharing options...
Steven P Posted April 10 Share Posted April 10 (edited) As above, what is your desired result (in words not code)? CAD is in the office tonight, CBAd packing it all up to bring home, but, and without checking these are just ideas: (while (/= (getvar 'cmdactive) 0) ; Check if a command is active (setq ss (ssget)) ; Prompt the user to select objects could be (while (setq ss (ssget)) ; Prompt the user to select objects (if the user selects something continue in the loop. Can then get rid of the next 'if' command (setq numJoined (getvar 'cmdresult)) I'll need the work laptop to confirm what the output from join is - can't remember if it is just a command line prompt or if you can grab it in LISP Edited April 10 by Steven P 1 Quote Link to comment Share on other sites More sharing options...
Steven P Posted April 11 Share Posted April 11 An update, in the office again.... If you want to count how many lines were joined, numJoined, I don't think you can do it with a simple 1 line command. Perhaps some reordering of the code is needed, as far as the user sees, they are only asked to select the line to join TO as an extra thing: To count joining polylines, select the line to join TO, then the selection set. Get the joining line coordinates (from the selection set) (use mAssoc, a search will get you this) - these are lists. After joining get the (modified) original line coordinates.... which should now contain the coordinates of any joined line. Now compare each list, if the coordinates are in both add a counter for joined lines. If counter = length of selection set then all lines were joined. If counter = 0 then no lines joined. Wonder if that makes sense.. the 'kers want me to do work now, so just a quick brain dump. 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.