Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*Expert Elite*
azrdgldr
Posts: 1,250
Registered: ‎01-09-2007
Message 11 of 13 (185 Views)

Re: Take two objects and swap their positions?

09-19-2011 11:42 AM in reply to: Kent1Cooper

You are correct, Sir.  I was just looking at it as the OP stated them (blocks) being simple light fixtures and me assuming that they would be on the same layer and such.

*Expert Elite*
Kent1Cooper
Posts: 5,606
Registered: ‎09-13-2004
Message 12 of 13 (183 Views)

Re: Take two objects and swap their positions?

09-19-2011 11:44 AM in reply to: pteague

pjtjr wrote:

My next question would be: How do I make the function work with two blocks that I have already selected?


If you have them in a selection set made with (ssget) or (ssadd) or something [let's call it ss], and there's nothing else in that selection set:

 

  (setq
    b1 (ssname ss 0))
    b2 (ssname ss 1))
....

 

and the rest the same.

 

If you have their entity names separately stored in variables, just remove the lines setting b1 & b2, and replace b1 & b2 in the rest of the code with the variable names you've already got.

Kent Cooper
Valued Mentor
alanjt_
Posts: 483
Registered: ‎08-25-2008
Message 13 of 13 (155 Views)

Re: Take two objects and swap their positions?

09-20-2011 09:47 AM in reply to: Kent1Cooper

I used VL to avoid the issue of annotative blocks in some cad versions.

 

(defun c:Test (/ ss lst)
  (vl-load-com)
  (if (setq ss (ssget "_:L" '((0 . "INSERT"))))
    (if (eq (sslength ss) 2)
      (mapcar 'vla-put-insertionpoint
              (setq lst (mapcar '(lambda (i) (vlax-ename->vla-object (ssname ss i))) '(0 1)))
              (mapcar 'vla-get-insertionpoint (reverse lst))
      )
      (princ "Selection amount must be equal to 2!")
    )
  )
  (princ)
)

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.