Jump to content

Join several lines or polylines lying on the same straight line in pairs.


Recommended Posts

Posted (edited)

It is necessary to join several segments or polylines lying on the same straight line in pairs.
But this code only works with lines. Is it possible for this to work with polylines as well?
LINE, LWPOLYLINE, POLYLINE

(defun c:JoinPairs ( / ent1 ent2 )
  (princ "\nSelect the first line or press Enter/ESC to finish.")
  (while (setq ent1 (car (entsel "\nFirst line for JOIN: ")))
    (setq ent2 (car (entsel "\nSecond line for JOIN: ")))
    (if ent2
      (command "_.JOIN" ent1 ent2 "")
      (progn
        (prompt "\nThe second line is not selected. Exit.")
        (exit)
      )
    )
  )
  (princ "\nJoin Pairs command is completed.")
  (princ)
)

 

Join.png

Edited by Nikon
  • Nikon changed the title to Join several lines or polylines lying on the same straight line in pairs.
Posted (edited)

Hi Nikon

 

If you explode a lwpolyline you will have a line. So you just have to break it up and delete the original.
Simply replace '(command "_.JOIN" ent1 ent2 "")' with the code I have attached

 

(progn
	(if (= (cdr (assoc 0 (entget ent1))) "LWPOLYLINE")
	  (setq ent (vlax-vla-object->ename (car (vlax-safearray->list (vlax-variant-value (vla-explode (vlax-ename->vla-object ent1))))))
		x (vla-delete (vlax-ename->vla-object ent1))
		ent1 ent
	  )
	)
	(if (= (cdr (assoc 0 (entget ent2))) "LWPOLYLINE")
	  (setq ent (vlax-vla-object->ename (car (vlax-safearray->list (vlax-variant-value (vla-explode (vlax-ename->vla-object ent2))))))
		x (vla-delete (vlax-ename->vla-object ent2))
		ent2 ent
	  )
	)
        (command "_.JOIN" ent1 ent2 "")
      )

 

Edited by GLAVCVS
  • Like 1
Posted (edited)
  On 1/30/2025 at 8:07 PM, GLAVCVS said:

If you explode a lwpolyline you will have a line. So you just have to break it up and delete the original.
Simply replace '(command "_.JOIN" ent1 ent2 "")' with the code I have attached

Yes, this is a great option! Thank you very much!

(defun c:JoinPairsGL ( / ent1 ent2 )
  (princ "\nSelect the first line or press Enter/ESC to finish.")
  (while (setq ent1 (car (entsel "\nFirst line for JOIN: ")))
    (setq ent2 (car (entsel "\nSecond line for JOIN: ")))
    (if ent2
    ;  (command "_.JOIN" ent1 ent2 "")
(progn
	(if (= (cdr (assoc 0 (entget ent1))) "LWPOLYLINE")
	  (setq ent (vlax-vla-object->ename (car (vlax-safearray->list (vlax-variant-value (vla-explode (vlax-ename->vla-object ent1))))))
		x (vla-delete (vlax-ename->vla-object ent1))
		ent1 ent
	  )
	)
	(if (= (cdr (assoc 0 (entget ent2))) "LWPOLYLINE")
	  (setq ent (vlax-vla-object->ename (car (vlax-safearray->list (vlax-variant-value (vla-explode (vlax-ename->vla-object ent2))))))
		x (vla-delete (vlax-ename->vla-object ent2))
		ent2 ent
	  )
	)
        (command "_.JOIN" ent1 ent2 "")
      )
      (progn
        (prompt "\nThe second line is not selected. Exit.")
        (exit)
      )
    )
  )
  (princ "\nJoin Pairs command is completed.")
  (princ)
)

 

Edited by Nikon
Posted

I think this was asked recently else where, I used JOIN which works for lines.

  • Thanks 1

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