Jump to content

"Swap" lisp doesn't work in Acad 2010


Diedesigner

Recommended Posts

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)
) 

Link to comment
Share on other sites

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)
)
   

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...