AutoLISP: Updated Heal Line/Polyline

There were 2 posts from a while back that did the same thing – Erase a selected block and then heal the LINE or POLYLINE, but the annoying thing was that only one routine would work for LINES and you would need another LISP routine for it to work for polylines.

Someone asked if these could be combined into 1 LISP routine over at and luckily PBE came up with the solution:

Please see the previous posts to see examples (animated gifs) of what the routine does:

Use the command EE to start

; by PBE
; erase a block and join the lines that the block broke
(defun c:hint ()
   (if	(setq ss (ssget '((0 . "INSERT"))))
   		(repeat (setq i (sslength ss))
		  	(setq pt  (cdr
				 (assoc  10
				     (setq e (ssname ss (setq i (1- i))))
		  	(command "_rotate" e "" "_non" pt "180")

(defun c:ee (/ pea $blk block i ll ur objs p1 p2)
  (setq pea (getvar 'Peditaccept))
  (setvar 'PeditAccept 1)
  (if (setq $blk (ssget '((0 . "insert"))))
	  (repeat (setq i (sslength $blk))
	    	(setq e (ssname  $blk (setq i (1- i))))
	  	(vla-getboundingbox (vlax-ename->vla-object e) 'll 'ur)
	    	(entdel e)
	  (setq objs (ssget "C" 
	      (setq p1 (vlax-safearray->list ll))
	      (setq p2 (vlax-safearray->list ur))
	(if (eq (cdr (assoc 0 (entget (ssname objs 0)))) "LWPOLYLINE")
		  (command "_.pedit"  "_m"  objs
			   ""  "_join" "_Joint"
			   "_Both" (distance p1 p2)
			   "" )
		  (command "_.join" (ssname objs 0) (ssname objs 1) "")
    (princ "\nNo Blocks Selected")
	  (setvar 'PeditAccept pea)

About AutoCAD Tips

This blog serves as a knowledge base for myself (and anyone else) so that I can reference tips & tricks that I have learned and also refer others to it as well. I hope that this blog helps you learn at least one tip to make your drafting/design experience better.
This entry was posted in AutoLISP, AutoLISP: Blocks, AutoLISP: Modify, AutoLISP: Polylines, Modifying, Uncategorized. Bookmark the permalink.

2 Responses to AutoLISP: Updated Heal Line/Polyline

  1. Filip Van Orshaegen says:

    Maybe usefull, I added (command “.-overkill” (ssname objs 0) “” “”) after
    (command “_.join” (ssname objs 0) (ssname objs 1) “”)
    This code replaces the vertex that filled-up the gap of the deleted block en that is in line with the next vertices by one vertex.

  2. Zagor_Dmtr says:

    For localized versions of AutoCAD (Russian, Germany, Italian etc.) you need to add “_” before “C” in SSGET: (setq objs (ssget “_C”…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s