LINEMERGE finds lines that lie along the same straight and joins them into single lines. A wall drawn in eight pieces because it was trimmed round doorways becomes one. Fragments left over from a scan trace, a bad DXF import or years of editing collapse into what they were meant to be.
What LineMerge does
Gaps are bridged up to a tolerance you set, so a run broken by a door is rejoined if you want it to be and left alone if you do not.
Why not just use JOIN? It needs the lines to be collinear and requires you to pick them in a set it can reason about. It will not sift a hundred selected lines into the twelve straights they belong to.
How to use it
- Load the routine with
APPLOAD, or put it on your support file search path. - Type
LINEMERGE. - Select the lines — a whole wall, a whole imported layer, whatever needs tidying.
- Give the gap tolerance. Zero merges only lines that actually touch.
How it works
The sifting is the whole routine. Lines are grouped by direction first, then by which straight line each one actually sits on, then merged along each straight in turn.
That ordering matters. Grouping by direction alone puts two parallel walls ten metres apart in the same group; grouping by straight is what separates them.
What it must not do is take the whole selection, find the largest and smallest X and Y across all of it, and draw one line across that bounding box. That turns two parallel walls into a single diagonal between their far corners, and only gives the right answer when every line picked was already part of the same straight — which is the one case where you did not need the routine.
Notes and limits
- Set the tolerance deliberately. Too generous and a doorway closes up; too tight and nothing merges.
- Lines only. Polylines are a different job.
- Properties come from the lines being merged, so mixing layers in one selection gives an arbitrary result — select by layer.
- One undo group covers the whole selection.
Download and details
| Name | LineMerge — join collinear lines into single lines |
| Download | LineMerge.lsp — 9.0 KB, plain AutoLISP source. Downloads directly; no zip to unpack. |
| Type | AutoCAD AutoLISP routine |
| Command | LINEMERGE |
| Requires | nothing beyond a CAD platform with AutoLISP. |
| Source size | 9.0 KB, 205 lines |
| Error handling | Yes — a *error* handler restores every system variable it changed, on cancel as well as on error. |
| Undo | The whole operation is wrapped in a single undo group, so one U reverses all of it. |
| Compatibility | AutoCAD (any release with AutoLISP), BricsCAD, ZWCAD, GstarCAD, ProgeCAD and other IntelliCAD-based platforms. AutoCAD LT needs a LISP enabler. No .NET, no ObjectARX, no installer. |
| Author | YZ, August 2026 |
| Licence | Free to use, supplied “as is” with no warranty. |
References
- HPGLIN LISP — the imports that most often need this afterwards
- FOLLOWON LISP — select a connected chain before merging it
- GRIDSNAP LISP — pulling near-collinear lines properly collinear first
- More free AutoLISP routines on this site
- Wisey’s Steel Shapes — free structural steel section drawing program