[Search tip detail and code files using keywords, tip number, author name, etc ]
 
    For tip to function correctly, you must ensure that the downloaded file name matches the file name
    displayed in the Rename File To field. Please rename downloaded files when necessary.
Swap Selection Sets
Tip# 3840 By Richard Paquette On 19-Mar-2012
2.5
Rated By 2 users Downloaded : 627
Categories : LISP Code Modules
Software type : AutoCAD 2012
Rename File To : SWAP.LSP
Transpose lines of text or other selection sets.

Tipster Richard Paquette shares a LISP routine called Swap that he has been using for a long time in AutoCAD. He has had it so long that he doesn’t know where he got it, but he loves it.

"The Swap routine does exactly as its name implies: It swaps one selection set with another. If its two lines of text you want to swap, just press Enter when it asks for the reference point; it uses the text object’s insertion point as the reference point. I use this routine often when I have to arrange items on my drawings. I can select a whole detail and swap places with another detail. It saves me from moving and moving and moving."

Notes from Cadalyst Tip Reviewer Brian Benton:
Cadalyst CAD Tip No. 1932 is a routine by Leonid Nemirovsky called SWAP.LSP; it works like this routine does, but only with text. This tip is easy enough to use. Load the routine and type SW on the Command line to start it. Select your first object (or objects) and press Enter. Next, select a reference point (similar to the Move command, this is the point where the objects will be moved from). Press Enter. Choose your second set of objects and their reference point. Both sets will be swapped and inserted according to the selected reference points.

 

Average Rating:
2.5


User comments
Comment by Elrod,K
Posted on 2012-03-19 13:50:04
I have been using this lisp for a long time as well, it is TIP763.
Comment by Koulik,Alexey
Posted on 2012-03-19 13:51:54
It's not too good code: 1. There are no UndoMarks 2. If user press Esc during (setq ss1 (ssget)), code will crashes. 3. User can select object on locked layers 4. User can select REGION or 3DPOLYLINE - there are no filters. 5. If error appears during executing command "_.move", osmode won't return to is start value.
Comment by Cooper,Kent
Posted on 2012-04-16 11:22:20
In response to K Elrod: Tip 763 is operationally similar, but not the same code -- it's much more basic (and a lot shorter) than this one. It always asks for the User to specify a base point for each selection set, whereas this one has the option, when there's only one thing selected and it has some kind of logical base point of its own, to use that. In response to Alexey Koulik, I don't think your item 4 is an issue. There's no reason a User shouldn't be allowed to select any and every kind of object(s) to swap the locations of. The routine doesn't filter in the selection, but for objects without their own logical reference point, it won't let you try to use such a point, because it gives you that option only for entity types that DO have such a thing, and only if the selection is of only one object. I agree with your other "complaints," and I would add one: there are additional entity types that have some kind of logical reference point, which should be added [e.g. Ellipse, Wipeout, Image, Leader, Mtext, Rtext, Point, maybe some others in newer versions than my 2004]. Some of those may be missing from the original code just because they may not have existed in AutoCAD when it was written.
Comment by Cooper,Kent
Posted on 2012-04-16 13:16:39
Here's an version that's upgraded, streamlined, with error handling and other controls added, that works like the original but that I believe overcomes Alexey Koulik's concerns, and also adds more entity types that can have their own insertion or other logical reference locations used if they're selected alone.
Comment by Cooper,Kent
Posted on 2012-09-12 10:23:29
Here's an upgraded version of Swap.lsp and its SW command. It uses the true insertion point for Text of any justification, rather than always the left end of the base line as it did before [the insertion point is a different entry in the entity data for Text that's other than left-justified].