• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
blog.draftsperson.net

blog.draftsperson.net

the art of technical drawing

blog.draftsperson.net

LINEMERGE LISP: Merge Collinear Lines Into One

August 6, 2026

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

  1. Load the routine with APPLOAD, or put it on your support file search path.
  2. Type LINEMERGE.
  3. Select the lines — a whole wall, a whole imported layer, whatever needs tidying.
  4. 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

NameLineMerge — join collinear lines into single lines
DownloadLineMerge.lsp — 9.0 KB, plain AutoLISP source. Downloads directly; no zip to unpack.
TypeAutoCAD AutoLISP routine
CommandLINEMERGE
Requiresnothing beyond a CAD platform with AutoLISP.
Source size9.0 KB, 205 lines
Error handlingYes — a *error* handler restores every system variable it changed, on cancel as well as on error.
UndoThe whole operation is wrapped in a single undo group, so one U reverses all of it.
CompatibilityAutoCAD (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.
AuthorYZ, August 2026
LicenceFree 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

Filed Under: AutoLISP Routines

Primary Sidebar

Subscribe to our Youtube Channel

Post CAD drafting jobs on Freelancer.com. and get some free money to do this.

Categories

  • American Steel Industry (4)
  • AutoCAD Articles & Reference (30)
  • AutoCAD Bugs & Problems (19)
  • AutoCAD Tips (29)
  • AutoCAD Tutorials (54)
  • AutoLISP Routines (328)
  • AutoLISP Tutorials (15)
  • CAD Standards (7)
  • Civil 3D (7)
  • Civil Drafting (4)
  • Dimensions (2)
  • Drafting Funnies (71)
  • Drafting History (9)
  • Drafting Standards (84)
  • Electrical Drafting (2)
  • General IT reference (7)
  • Geometry (15)
  • GIS (2)
  • Hatch Patterns (12)
  • Office Life Hacks (3)
  • PT (1)
  • Revit Tutorials (54)
  • Steel Detailing (14)
  • Structural Drafting (26)
  • Technical Dictionary (61)
  • Useful Website Links (19)

Footer

Free downloads

  • Free AutoLISP routines
  • Free hatch patterns
  • SHX fonts & text styles
  • Numbering LISP collection
  • ISO 3098B font

Reference charts

  • AWS weld symbols chart
  • Steel detailing chart
  • Hole & slot sizes
  • Bolt edge distance
  • ANSI & ARCH paper sizes
  • How to fold an A1 drawing

Useful links

  • CAD blocks (DWG)
  • Revit families
  • structuraldrafter.com
  • cad-corner.com
  • About
  • Privacy policy

Provided for free with no warranty · Log in