Here's one I came up with a while back that was designed for creating intersections where four entities cross. It breaks the objects at the crossing points.
It actually lets you select any number of entities (lines, arcs, polylines, splines), and then will erase the gap between intersections on all objects that cross two and only two of the other objects. If you make a grid of lines and play with it, you should get a feel for how it works. (It will also break circles, but with unpredictable results...)
; itrim.lsp v1.01
; takes a selection set, and trims the gap between intersection points for
; all objects that intersect two and only two of the other objects in the set
; Richard Sincovec, July 11 2004
; Bug fixes - July 30, 2004
(vl-load-com)
(defun c:itrim (/ acadObj doc ssets ss count err
i j items item intxlist intitem
osmode
)
(setq osmode (getvar "osmode")
acadObj (vlax-get-acad-object)
doc (vla-get-activeDocument acadObj)
ssets (vla-get-selectionSets doc)
err (vl-catch-all-apply
(function
(lambda ()
(setq ss (vla-add ssets "ZYZ_ITRIM"))
) ;lambda
) ;function
) ;vl-catch-all-apply
) ;setq
(if (vl-catch-all-error-p err)
;; error is probably "ss already exists"
;; it shouldn't yet, but use it if it does
(setq ss (vla-item ssets "ZYZ_ITRIM"))
) ;if
(setq err (vl-catch-all-apply
(function
(lambda ()
(while ; (MAIN)
(progn
(vla-clear ss)
(vla-selectOnScreen ss)
(setq count (vla-get-count ss))
(/= count 0)
) ;progn
(setq i count
items nil
) ;setq
(setvar "osmode" 0)
(while (/= i 0)
(setq i (1- i)
item (vla-item ss i)
j count
intxlist nil
) ;setq
(while (/= j 0)
(setq j (1- j)
intitem (vla-item ss j)
) ;setq
(if (/= (vla-get-handle item)
(vla-get-handle intitem)
) ;_ /=
(progn
(setq intx (vlax-variant-value
(vla-IntersectWith
item
intitem
acExtendNone
) ;_ vla-IntersectWith
) ;_ vlax-variant-value
) ;_ setq
(if (safearray-value intx)
(setq
intxlist
(append
intxlist
(list (vlax-safearray->list intx))
) ;_ append
) ;setq
) ;_ if
) ;_ progn
) ;if
) ;while j
;; if we found two and only two intersections, store the entity for breaking
;; if we break it now, it will confuse the rest of the intersection checking
(if (= (length intxlist) 2)
(setq
items
(append
items
(list (cons (vlax-vla-object->ename item)
intxlist
) ;_ cons
) ;_ list
) ;_ append
) ;_ setq
) ;if
) ;while i
;; break the items
(foreach item items
(command "break"
(list (car item) (cadr item))
(caddr item)
) ;_ command
) ;foreach
) ;while (MAIN)
) ;lambda
) ;function
) ;vl-catch-all-apply
) ;setq
(if (vl-catch-all-error-p err)
(princ (vl-catch-all-error-message err))
) ;if
(setvar "osmode" osmode)
(vla-delete ss)
(princ)
) ;defun