Dev.to WebDev 🛠 Dev 👁 0 📖 4 min read

Generating Valid AutoCAD R12 (AC1009) ASCII .DXF Floor Plans in TypeScript: 8 AIA Layers and $INSUNITS=1

Many web-based floor plan apps lock users into raster .PNG exports or proprietary project formats that contractors, drafters, and cabinet makers cannot open in AutoCAD, Revit, SketchUp, LibreCAD, or QCAD. When a web app

Many web-based floor plan apps lock users into raster .PNG exports or proprietary project formats that contractors, drafters, and cabinet makers cannot open in AutoCAD, Revit, SketchUp, LibreCAD, or QCAD. When a web app does claim .DXF support, it often writes flat single-layer geometry (layer 0) with inverted Y-axes or arbitrary unitless coordinates that force hours of manual cleanup.

In this engineering deep dive, we break down how to generate clean, universal AutoCAD R12 (AC1009) ASCII .DXF floor plans directly in TypeScript with US imperial inches ($INSUNITS=1), Y-up CAD coordinates, and 8 structured AIA CAD layers.

Test the live browser CAD studio and inspect a real blueprint sheet or .DXF export here: PlanCaliber Online Blueprint & DXF Maker.

1. Why AutoCAD R12 (AC1009) Beats Newer DXF Versions for Web Export

AutoCAD DXF versions AC1015 (R2000) and newer mandate strict object handle graphs (HANDSEED), CLASSES, OBJECTS, and dictionary ownership pointers (330 owner handles). One missing handle causes AutoCAD or Revit to reject the entire file with an unhandled import error.

By contrast, AutoCAD R12 (AC1009) ASCII DXF:

  • Opens cleanly in every modern CAD platform (AutoCAD 2026, AutoCAD LT, Revit, SketchUp Pro, BricsCAD, Chief-compatible importers, LibreCAD, QCAD, and Blender).
  • Requires only HEADER, TABLES (LTYPE + LAYER), and ENTITIES sections (LINE, ARC, CIRCLE, TEXT, POLYLINE).
  • Keeps file sizes tiny (15 KB to 90 KB for a full residential floor plan) and human-readable for automated unit tests.

2. Setting US Imperial Inches ($INSUNITS=1) and Flipping Screen Y-Axis

HTML <canvas> and SVG place (0, 0) at the top-left with Y increasing downward. CAD software places (0, 0) at the bottom-left with Y increasing upward. If you skip flipping Y, every floor plan imports upside-down in AutoCAD.

export function createDxfWriter(maxYInches: number) {
  const lines: string[] = [];
  const push = (code: number, val: string | number) => {
    lines.push(String(code), String(val));
  };
  const fmt = (n: number) => Number(n.toFixed(4)).toString();
  const flipY = (y: number) => maxYInches - y;

  // HEADER: AC1009 + US inches ($INSUNITS = 1, $LUNITS = 4 imperial feet-inches)
  push(0, 'SECTION');
  push(2, 'HEADER');
  push(9, '$ACADVER'); push(1, 'AC1009');
  push(9, '$INSUNITS'); push(70, 1);
  push(9, '$MEASUREMENT'); push(70, 0); // 0 = English/Imperial
  push(9, '$LUNITS'); push(70, 4);      // 4 = Feet & Inches display
  push(0, 'ENDSEC');

  const addLine = (
    layer: string,
    x1: number,
    y1: number,
    x2: number,
    y2: number,
    ltype = 'CONTINUOUS'
  ) => {
    push(0, 'LINE');
    push(8, layer);
    push(6, ltype);
    push(10, fmt(x1)); push(20, fmt(flipY(y1))); push(30, '0');
    push(11, fmt(x2)); push(21, fmt(flipY(y2))); push(31, '0');
  };

  return { push, addLine, toString: () => lines.join('\r\n') + '\r\n' };
}

Notice the \r\n CRLF line endings: several legacy desktop CAD parsers on Windows expect standard CRLF pairs for DXF group codes and values.

3. Structuring 8 Standard AIA CAD Layers (ACI Colors)

Putting walls, door swings, electrical symbols, and dimensions onto separate named layers lets any contractor or drafter toggle electrical or furniture visibility in one click:

Layer Name ACI Color Purpose
A-WALL 7 (White/Black) Exterior & interior double-line wall geometry
A-DOOR 30 (Orange) Door jambs, leaves, and 90-degree swing arcs
A-GLAZ 4 (Cyan) Windows, egress glazing, and glass panes
A-CABN 8 (Dark Gray) Kitchen base/wall cabinets, islands, vanities, appliances
A-FURN 9 (Light Gray) Beds, sofas, tables, desks, movable furniture
E-POWR 2 (Yellow) NEC duplex/GFCI outlets, switches, recessed fixtures
A-ROOM 3 (Green) Room names, dimensions, and interior sq ft labels
A-DIMS 6 (Magenta) Exterior dimension strings, ticks, and extension lines

Defining each layer cleanly inside the TABLES -> LAYER block ensures every CAD viewer renders proper layer colors immediately on open:

const AIA_LAYERS: { name: string; color: number }[] = [
  { name: 'A-WALL', color: 7 },
  { name: 'A-DOOR', color: 30 },
  { name: 'A-GLAZ', color: 4 },
  { name: 'A-CABN', color: 8 },
  { name: 'A-FURN', color: 9 },
  { name: 'E-POWR', color: 2 },
  { name: 'A-ROOM', color: 3 },
  { name: 'A-DIMS', color: 6 }
];

4. Pairing Layered .DXF with Scaled 1/4"=1'-0" Vector PDF Sheets

While drafters and trades want .DXF, homeowners, inspectors, and real estate teams want clean printable sheets. In PlanCaliber, the exact same parametric wall/opening/fixture graph drives:

  • Free Studio Draft ($0): Full 2D/3D CAD drafting, 40 US starter templates, 50 live US code calculators, 2 free AI sketch/PDF scans/day, instant watermarked 1400x1050 proof PNG, and free watermarked 2D/3D share link.
  • One-Time Print Pass ($9): Clean unwatermarked 2-sheet vector PDF (A-101 scaled 1/4"=1'-0" plan + M-101 clean presentation sheet), 2400px PNG, SVG, custom title block, permanent edits & re-downloads.
  • One-Time Full CAD Pack ($19, or $49 5-Plan Pack): 5-sheet 1/4"=1'-0" vector PDF (A-101, A-102, E-101, A-201, M-101), the full 8-layer AutoCAD R12 .DXF ($INSUNITS=1), 3D .OBJ/.MTL mesh, and framing/drywall takeoff .CSV.

All purchases include a 14-day instant no-questions-asked refund policy.

Disclaimer: Generated CAD sheets, .DXF files, and takeoffs are intended for preliminary space planning and estimating only. Field-verify measurements on site and confirm local AHJ building code requirements prior to construction.

Draft and Export Your Blueprint Now

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.