Jump to content

Swap objects


itacad

Recommended Posts

Hi, I think I found the lisp that I am attaching on this forum.
It is a very useful lisp, it allows you to move two blocks between them, swapping their positions, using the insertion point of both.

Unfortunately it has the limitation that it only works with blocks.

Could it be correct to swap the position of all objects that have an insertion point?

thank you very much

 

 

 

SWAP.LSP

  • Confused 1
Link to comment
Share on other sites

UU (utterly untested)


(defun c:swap ( / ss l) (vl-load-com) (princ "\nSelect 2 objects with insertionpoint : ")
  (cond ((not (setq ss (ssget "_:L")))(alert "Selection cancelled"))
    ((not (= 2 (sslength ss))) (alert (strcat "You selected " (sslength ss) " objects")))
    ((not (vl-every 'vl-consp (setq l (mapcar '(lambda (i)(getip (vlax-ename->vla-object (ssname ss i)))) '(0 1)))))
     (alert "Insertionpoint error")) (t (putip (cadar l) (caadr l)) (putip (cadadr l) (caar l))))(princ))

(defun getip (o) (cond ((vlax-property-available-p o 'TextAlignmentPoint)
  (if (= (vla-get-alignment o) 0)(list (vla-get-InsertionPoint o) o)(list (vla-get-TextAlignmentPoint o) o)))
    ((vlax-property-available-p o 'InsertionPoint)(list (vla-get-InsertionPoint o) o))))

(defun putip (o p) (if (and (vlax-property-available-p o 'TextAlignmentPoint)(/= (vla-get-alignment o) 0))
  (progn (vla-put-insertionpoint o p)(vla-put-TextAlignmentpoint o p))(vla-put-insertionpoint o p)))

Link to comment
Share on other sites

Not sure how many objects have a Insertion point may be better as a series of defuns could swap a line and a block. 

 

Just thinking

Block Insertion point

*Text has as suggested alignment point

Arc & Circle centre point

Line start pt, mid , end

Pline 1st vertice or (GC)

hatch has a pt

 

Need Itacad to narrow down what is to be swapped and the rules.

Edited by BIGAL
Link to comment
Share on other sites

Hello and thanks in the meantime.

By insertion point I meant what is considered such by the object snap.

For example, texts have an insertion point...for other types of objects (lines, polygons, etc.) I don't need them.

Greetings

 

Link to comment
Share on other sites

@itacad, maybe some like it 

 

(setq ss (ssget "_:L" '((0 . "INSERT,metxt,text"))))

 Maybe you will need to check if selection hold same entities  kind , 
 

Edited by devitg
Link to comment
Share on other sites

🤔...Srry but I did not understand the suggestion of devitg...

 ...I tried to replace the line of code but it doesn't work ... regards

Link to comment
Share on other sites

This line , if it is typed correctly, allow to select BLOCKREFERENCE  [INSERT], MTEXT,TEXT 

(setq ss (ssget "_:L" '((0 . "INSERT,MTEXT,TEXT"))))

 

 

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