AutoCAD Automation: BreakAll.lsp — Split Entities at Every Intersection
Program Description
BreakAll.lsp is a production-grade AutoLISP routine built to eliminate repetitive manual trimming in AutoCAD. The BRKALL command scans a selection of lines, polylines, arcs, and splines, detects every valid intersection, and executes a precise break operation at each point.
Unlike manual workflows using native commands such as TRIM or BREAK, this routine is designed to handle dense, overlapping geometry without losing entity integrity. Two core mechanisms make it reliable in real-world drawings:
- A tolerance engine (1e-6) that filters out near-duplicate points and floating-point noise
- A reverse parameter sorting algorithm that prevents invalid entity states during sequential breaks
This combination ensures that every segment is split correctly, even in messy survey imports or CAD files coming from external sources.
Typical use cases include:
- Cleaning up site plans and GIS imports
- Preparing geometry for CNC or laser cutting
- Creating topologically clean networks for analysis
- Splitting linework before block generation or quantity takeoffs
Download the script here
Step-by-Step Guide to Using BRKALL
Load the Script
Drag and drop the BreakAll.lsp file into the AutoCAD drawing window, or run APPLOAD and browse to the file.
If you frequently use LISP tools, consider adding it to the Startup Suite in APPLOAD.
Reference:
https://help.autodesk.com/view/ACD/2024/ENU/?guid=GUID-APPLOAD
Initialize the Command
Type BRKALL in the command line and press Enter.
No dialog boxes. The command runs directly in the command line, which keeps it fast and scriptable.
Select Geometry
Use any selection method (window, crossing, filter) to pick objects.
The routine automatically filters for:
- LINE
- ARC
- LWPOLYLINE
- POLYLINE
- SPLINE
Circles and ellipses are intentionally excluded. They require different handling for single-point breaks.
Automatic Processing
After selection:
- The routine computes all pairwise intersections
- Groups intersection points per entity
- Removes duplicates using the tolerance threshold
- Sorts points from end → start using curve parameters
- Executes the BREAK command sequentially
This order is critical. Breaking from start → end can invalidate subsequent points.
Review Results
Once complete:
- The command line displays how many objects were processed
- Every intersection becomes a node, and every segment becomes independent
At this point, your geometry is ready for:
- trimming
- topology checks
- export workflows
Full AutoLISP Program
;;; ==========================================================================
;;; Command: BRKALL
;;; Description: Breaks selected Lines, Arcs, Polylines, and Splines at
;;; every intersection point using a tolerance-based approach.
;;; ==========================================================================
(defun c:BRKALL (/ old-os old-cmd doc ss i j entList ent1 ent2 obj1 obj2
pts k ptGrp pt brkData curve p item tol ptList isDuplicate)
(vl-load-com)
;; --- TOLERANCE PARAMETER ---
;; Prevents creating micro-segments by ignoring points within this distance.
(setq tol 1e-6)
;; Setup Undo mark and save system variables
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vla-startundomark doc)
(setq old-os (getvar "OSMODE"))
(setq old-cmd (getvar "CMDECHO"))
(setvar "OSMODE" 0)
(setvar "CMDECHO" 0)
(princ "\nSelect objects to break at intersections: ")
;; Selection filter: Only breakable linear/curve objects.
;; Note: Circles and Ellipses are excluded as they require specific logic for single-point breaks.
(if (setq ss (ssget '((0 . "LINE,ARC,LWPOLYLINE,SPLINE,POLYLINE"))))
(progn
(setq i 0)
(setq entList nil)
;; 1. Collect all selected entities into a list
(while (< i (sslength ss))
(setq entList (cons (ssname ss i) entList))
(setq i (1+ i))
)
;; 2. Find intersections between all pairs
(setq brkData nil)
(setq i 0)
(while (< i (1- (length entList)))
(setq ent1 (nth i entList))
(setq obj1 (vlax-ename->vla-object ent1))
(setq j (1+ i))
(while (< j (length entList))
(setq ent2 (nth j entList))
(setq obj2 (vlax-ename->vla-object ent2))
;; Get intersection points (acExtendNone = only real intersections)
(setq pts (vlax-invoke obj1 'IntersectWith obj2 acextendnone))
(if pts
(progn
;; Group coordinates into 3D points (X Y Z)
(setq k 0 ptGrp nil)
(while (< k (length pts))
(setq pt (list (nth k pts) (nth (+ k 1) pts) (nth (+ k 2) pts)))
(setq ptGrp (cons pt ptGrp))
(setq k (+ k 3))
)
;; Process each point and add it to the break data if it's not a duplicate
(foreach p ptGrp
;; Update Entity 1
(setq ptList (cdr (assoc ent1 brkData)))
(setq isDuplicate nil)
(foreach existingPt ptList
(if (< (distance p existingPt) tol) (setq isDuplicate T))
)
(if (not isDuplicate)
(if (assoc ent1 brkData)
(setq brkData (subst (cons ent1 (cons p ptList)) (assoc ent1 brkData) brkData))
(setq brkData (cons (list ent1 p) brkData))
)
)
;; Update Entity 2
(setq ptList (cdr (assoc ent2 brkData)))
(setq isDuplicate nil)
(foreach existingPt ptList
(if (< (distance p existingPt) tol) (setq isDuplicate T))
)
(if (not isDuplicate)
(if (assoc ent2 brkData)
(setq brkData (subst (cons ent2 (cons p ptList)) (assoc ent2 brkData) brkData))
(setq brkData (cons (list ent2 p) brkData))
)
)
)
)
)
(setq j (1+ j))
)
(setq i (1+ i))
)
;; 3. Execute the Breaks
(if brkData
(progn
(foreach item brkData
(setq curve (car item))
(setq pts (cdr item))
(if (entget curve) ;; Verify entity still exists in the database
(progn
;; CRITICAL: Sort points by parameter in descending order (End to Start).
;; This ensures the entity handle remains valid for subsequent breaks on the same object.
;; Using 'getclosestpointto' handles floating-point precision issues.
(setq pts (vl-sort pts
'(lambda (p1 p2)
(> (vlax-curve-getparamatpoint curve (vlax-curve-getclosestpointto curve p1))
(vlax-curve-getparamatpoint curve (vlax-curve-getclosestpointto curve p2))
)
)
)
)
;; Run the AutoCAD BREAK command for each unique point
(foreach p pts
(command "._break" (list curve p) "_F" "_none" p "_none" p)
)
)
)
)
(princ (strcat "\nDone: " (itoa (length brkData)) " objects broken at intersections."))
)
(princ "\nNo intersections found.")
)
)
(princ "\nNo valid objects selected.")
)
;; Restore system variables and close Undo mark
(setvar "OSMODE" old-os)
(setvar "CMDECHO" old-cmd)
(vla-endundomark doc)
(princ)
)
(princ "\nBreakAll.lsp loaded. Type BRKALL to run.")
(princ)
Why Choose BRKALL for Your Workflow?
AutoCAD’s native tools handle individual edits well, but they don’t scale. If you’ve ever tried to clean a survey drawing with thousands of intersections, you already know the problem.
BreakAll.lsp addresses that directly.
Handles Large Intersection Sets
Manual trimming:
- requires repeated picks
- introduces human error
BRKALL:
- processes everything in one pass
- guarantees consistent results
Built-In Tolerance Control
The 1e-6 tolerance is not arbitrary.
It solves a real issue:
- imported geometry often contains almost-coincident points
- without tolerance, you get micro-segments and unstable topology
This routine filters those automatically.
Reliable Break Sequencing
Breaking entities changes their internal structure.
If done in the wrong order:
- points shift
- entities fail to split correctly
The reverse sorting algorithm ensures:
- stable execution
- no lost segments
Cleaner Data for Downstream Work
After running BRKALL, your drawing becomes:
- easier to analyze
- safer to export
- compatible with CAM tools and GIS systems
This is especially useful before:
- exporting to DXF
- running network analysis
- generating toolpaths
Advanced Notes (From Field Use)
Performance Considerations
The routine uses a pairwise comparison (O(n²)). That’s fine for most drawings.
For very large selections (1000+ objects):
- isolate areas
- process in batches
Precision vs Speed
Using the AutoCAD BREAK command instead of ActiveX methods is intentional:
- more stable across versions
- handles edge cases better (especially splines)
Known Limitations
- Does not process blocks (explode first if needed)
- Does not handle 3D polylines reliably
- Tangential intersections may not always produce clean splits
Best Practices
- Run OVERKILL before BRKALL to remove duplicates
https://help.autodesk.com/view/ACD/2024/ENU/?guid=GUID-OVERKILL - Use AUDIT after processing for database cleanup
- Work on a copy of the drawing when testing large datasets
FAQ
What objects are supported?
Lines, arcs, polylines, and splines.
Circles and ellipses are excluded due to how AutoCAD handles single-point breaks.
Why not just use TRIM?
TRIM requires manual selection and doesn’t handle mass intersections efficiently. BRKALL automates the entire process in one execution.
What does the tolerance value do?
The 1e-6 tolerance prevents:
- duplicate break points
- extremely small segments
It improves both performance and drawing stability.
Can I change the tolerance?
Yes. Modify this line in the LISP:
(setq tol 1e-6)
Increase it for messy survey data. Decrease it for high-precision mechanical drawings.
Why are some intersections not broken?
Possible causes:
- objects don’t actually intersect (visually close only)
- Z-values differ
- geometry is corrupted
Check using OSNAP intersection or run FLATTEN if needed.
Does it work on large drawings?
Yes, but performance depends on object count.
For heavy datasets, process in logical zones instead of selecting everything at once.
Is this safe for production drawings?
Yes. The routine includes:
- undo grouping
- entity validation
- duplicate filtering
Still, standard practice applies: test on a copy first.
Can this be combined with other automation?
Yes. Common workflows:
- BRKALL → OVERKILL → JOIN
- BRKALL → export to CAM
- BRKALL → topology scripts
If you deal with dense geometry regularly, BRKALL becomes a standard tool, not a one-off script.

