Diedesigner Posted May 12, 2010 Share Posted May 12, 2010 Hi all, I downloaded this lisp from the LukewarmCoffee website - it is authored by Jeff Rayhorn. It loads successfully, but when I type "swap" at the control line, I get an "Unknown command" error message. Is there anything obvious in the code that could cause the problem, or do I need to look deeper to see if it is conflicting with other lisps I have loaded? Any help would be greatly appreciated. ; c. 2006 Jeff Rayhorn & LukewarmCoffee.co_ (defun swap () (setvar "cmdecho" 0) (command "undo" "be") (prompt "\nSelect first group of objects, [ENTER] when done...") (setq frstset(ssget)) (setq frstpnt(getpoint "\nPick base point for the first group of objects...")) (prompt "\nSelect second group of objects, [ENTER] when done...") (setq scndset(ssget)) (setq scndpnt(getpoint "\nPick base point for the second group of objects...")) (command "move" frstset "" frstpnt scndpnt) (command "move" scndset "" scndpnt frstpnt) (command "undo" "e") (princ) ) Quote Link to comment Share on other sites More sharing options...
lpseifert Posted May 12, 2010 Share Posted May 12, 2010 try (swap) at the command line... untested or edit the code so the first line reads (defun c:swap () Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 12, 2010 Share Posted May 12, 2010 Another way to possibly write it: (defun c:swap (/ *error* Move s1 s2 p1 p2 ) ;; Lee Mac ~ 12.05.10 (vl-load-com) (defun *error* ( msg ) (and flag (vla-EndUndoMark doc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ)) (defun Move ( ss p1 p2 / v1 v2 ) (mapcar (function set) '(v1 v2) (mapcar (function vlax-3D-point) (list p1 p2))) ( (lambda ( n / e obj ) (while (setq e (ssname ss (setq n (1+ n)))) (if (vlax-method-applicable-p (setq obj (vlax-ename->vla-object e)) 'Move) (vla-move obj v1 v2) ) ) ) -1 ) ) (if (and (princ "\nSelect First Group of Objects...") (setq s1 (ssget "_:L")) (setq p1 (getpoint "\nPick First Base Point: ")) (princ "\nSelect Second Group of Objects...") (setq s2 (ssget "_:L")) (setq p2 (getpoint "\nPick Second Base Point: ")) (setq flag (not (vla-StartUndoMark (setq doc (vla-get-ActiveDocument (vlax-get-acad-object) ) ) ) ) ) ) (progn (mapcar (function Move) (list s1 s2) (list p1 p2) (list p2 p1) ) (setq flag (vla-EndUndomark doc)) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Diedesigner Posted May 12, 2010 Author Share Posted May 12, 2010 Editing it with (defun c:swap () worked. Thanks! Lee, the visual lisp version looks good too. I'm a relative noob to lisp; I've been more of a hacker over the years to get existing lisps to work the way I want. I'll study yours and compare it to the original for my own "education". Thanks again! -Chris Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 12, 2010 Share Posted May 12, 2010 Editing it with (defun c:swap () worked. Thanks! Lee, the visual lisp version looks good too. I'm a relative noob to lisp; I've been more of a hacker over the years to get existing lisps to work the way I want. I'll study yours and compare it to the original for my own "education". Thanks again! -Chris No worries, its just got a touch more error trapping, and will perhaps run a tad faster. Lee PS> Forgot to mention - your old LISP messes with your CMDECHO System variable and doesn't set it back. Quote Link to comment Share on other sites More sharing options...
alanjt Posted May 12, 2010 Share Posted May 12, 2010 LoL Nice one Lee. I actually updated an old one I wrote the other day. It will only swap one object with another (I use it to swap two blocks or a text object). (defun c:EW (/ *error* lst f) ;; Entity Swap ;; Alan J. Thompson, 06.05.08 / 07.10.08 / 05.01.10 (defun *error* (msg) (and f *AcadDoc* (vla-EndUndoMark *AcadDoc*)) (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*")) (princ (strcat "\nError: " msg)) ) ) (if (and (car (setq lst (cons (car (entsel "\nSelect first object: ")) lst))) (cadr (vl-remove nil (setq lst (cons (car (entsel "\nSelect second object: ")) lst)))) ) ((lambda (pts) (setq f (not (vla-StartUndoMark (cond (*AcadDoc*) ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))) ) ) ) ) (mapcar (function (lambda (o a b) (vl-catch-all-apply (function vla-move) (list o a b)))) (mapcar (function vlax-ename->vla-object) lst) pts (reverse pts) ) ) (mapcar (function (lambda (x) (vlax-3d-point (cdr (assoc 10 (entget x)))))) lst ) ) ) (*error* nil) (princ) ) Quote Link to comment Share on other sites More sharing options...
alanjt Posted May 13, 2010 Share Posted May 13, 2010 PS> Forgot to mention - your old LISP messes with your CMDECHO System variable and doesn't set it back. I actually set my to zero on startup. 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.