@Anonymous wrote:
.... I'm trying to create a command or a macro that could switch the insertion points of two objects. The first object would take the insertion point of the second and the second one would take the first object's insertion point. ....
In your example, yes, simply trading the text content is the easy way to do it. But your question got me thinking in terms of a more generic operation. This will switch the insertion points as requested of not just Text/Mtext, but also Blocks, Xrefs, Points, and [by their centers] Circles or Arcs, in any combination of two qualifying objects:
;|
SwapIns.lsp
To Swap the locations of any two objects with single insertion/base/reference
points [insertion points of Blocks/Xrefs/Text/Mtext, center points of Circles/
Arcs, locations of Points], giving each one's location to the other.
Kent Cooper, 5 June 2018
|;
(defun C:SwapIns (/ ss e1data e2data inscode1 inscode2 ins1)
(prompt "\nTo Swap the location of 2 objects,")
(if
(and
(setq ss (ssget ":L" '((0 . "INSERT,*TEXT,CIRCLE,ARC,POINT"))))
(= (sslength ss) 2)
); and
(progn ; then
(setq
e1data (entget (ssname ss 0))
e2data (entget (ssname ss 1))
); setq
(foreach num '("1" "2")
(set (read (strcat "inscode" num)); inscode1 or inscode2
(if
(and
(member '(0 . "TEXT") (setq edata (eval (read (strcat "e" num "data")))))
(not (and (member '(72 . 0) edata) (member '(73 . 0) edata))); not Left-justified
); and
11; insertion point (assoc) code of other-than-Left-justified plain Text
10; insertion point of Left-justified Text & all other object types
); if
); set
); foreach
(setq ins1 (cdr (assoc inscode1 e1data))); get before it might be replaced by next line
(entmod (subst (cons inscode1 (cdr (assoc inscode2 e2data))) (assoc inscode1 e1data) e1data))
(entmod (subst (cons inscode2 ins1) (assoc inscode2 e2data) e2data))
); progn
(prompt "\nNo appropriate object type(s) selected, or not 2-and-only-2 objects."); else
); if
(princ)
); defun
Some other object types could perhaps be added to it. And it could be made to ask again if you don't select exactly 2 of the right kind(s) of objects, instead of giving up. And it could use the usual enhancements [e.g. error handler, Undo begin/end wrapping]. But it seems to work in limited testing.
Kent Cooper, AIA