|

FlattenZ (FLATZ): The Ultimate AutoCAD AutoLISP to Flatten 3D Drawings to Z=0

Program Description

FlattenZ (FLATZ) is a high-performance AutoLISP utility built for CAD managers and production teams who need a fast way to eliminate “not coplanar” errors. It targets one of the most common issues in mixed 2D/3D drawings: inconsistent Z-values that break basic editing commands.

Unlike standard tools, FlattenZ uses a geometric projection method based on large-coordinate displacement to normalize object positions. It processes a wide range of entities—lines, polylines, arcs, blocks, and more—and forces them into a consistent working plane.

This tool is especially useful when dealing with:

  • Survey data imports (DWG, DXF, LandXML conversions)
  • Architectural backgrounds from external consultants
  • 3D models that must be reduced to clean 2D deliverables
  • Legacy drawings with accumulated Z-errors

The objective is simple: restore a reliable 2D environment where editing commands behave predictably.


Download the script here.


FLATZ AutoLISP Program

(defun c:FLATZ (/ ss old_cmdecho)
  (setq old_cmdecho (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)

  ;; Selection: Entire drawing (except viewports) if no manual selection is made
  (setq ss (ssget))
  (if (null ss) (setq ss (ssget "_X" '((0 . "~VIEWPORT")))))

  (if ss
    (progn
      (princ "\nCalcul de projection vers Z=0...")
      ;; La méthode "Magic" 1e99
      (command "_.MOVE" ss "" '(0 0 0) '(0 0 1e99))
      (command "_.MOVE" "P" "" '(0 0 0) '(0 0 -1e99))
      (princ "\nTerminé. Tout est à Z=0.")
    )
    (princ "\nErreur : Aucun objet trouvé.")
  )

  (setvar "CMDECHO" old_cmdecho)
  (princ)
)

Step-by-Step Usage Guide

Load the Script

  • Drag and drop FlattenZ.lsp directly into AutoCAD
  • Or use the APPLOAD command and optionally add it to the Startup Suite for automatic loading

Reference: https://help.autodesk.com/view/ACD/2024/ENU/?guid=GUID-0C8AF8B8-5E7E-4F7E-8D1E-9D1C7E9E9C21


Initialize the Command

  • Type FLATZ in the command line
  • Press Enter

Select Objects

  • Select objects manually
  • Or press Enter to process the entire drawing

The routine automatically:

  • Uses a global selection set
  • Excludes viewports to avoid layout corruption

Execute

  • The script runs instantly using a two-step displacement method
  • All selected entities are processed

Result:

  • Geometry is normalized for downstream operations
  • Drawing becomes usable for:
    • Trim
    • Extend
    • Fillet
    • Hatch
    • Dimensioning

How the FLATZ Method Works (Technical Breakdown)

The core logic relies on a controlled numerical behavior inside AutoCAD:

(command "_.MOVE" ss "" '(0 0 0) '(0 0 1e99))
(command "_.MOVE" "P" "" '(0 0 0) '(0 0 -1e99))

What this does

  • Applies an extreme displacement along the Z-axis
  • Forces AutoCAD to recompute object positioning using floating-point precision limits
  • Returns objects back after normalization

Why it works in practice

  • AutoCAD recalculates internal geometry during extreme transformations
  • In many cases, Z inconsistencies are neutralized during recomputation
  • Particularly effective on:
    • Imported DWG/DXF files
    • Dirty geometry with precision errors

What it does NOT guarantee

  • It does not explicitly rewrite Z = 0
  • It may not fix:
    • Objects with embedded elevation properties
    • Certain block definitions
    • 3D polylines or proxy objects

This is a pragmatic field solution, not a mathematical rewrite.


Technical SEO Optimization & Why It Matters

In production environments, “not coplanar” errors directly block workflow.

Typical failures include:

  • FILLET fails silently
  • TRIM does not intersect correctly
  • HATCH refuses closed boundaries
  • OFFSET produces inconsistent results

These issues are not cosmetic. They:

  • Waste production time
  • Introduce drawing errors
  • Delay deliverables

AutoCAD’s native FLATTEN command (Express Tools) often fails with:

  • Nested blocks
  • External references
  • Proxy objects

Reference: https://help.autodesk.com/view/ACD/2024/ENU/?guid=GUID-2B9E3A72-71AF-4E31-8F1B-0E3D7A0E0F6A


Why FLATZ is used in real workflows

  • Faster than manual cleanup
  • Works on full drawings without preprocessing
  • Fits into CAD standards templates
  • Useful in BIM coordination environments where multiple sources introduce Z-noise

Typical integration:

  • Loaded in startup LISP
  • Run before:
    • Export to DWG/DXF
    • Plotting
    • Sheet set creation

Best Practices from the Field

  • Run FLATZ after importing external data, not before
  • Combine with:
    • OVERKILL (geometry cleanup)
    • PURGE (remove unused data)
  • Avoid running on:
    • Active 3D modeling sessions
    • Drawings requiring true elevation data

If precision matters (survey-grade work):

  • Verify Z-values manually using:
    • LIST
    • ID
    • or (entget) in AutoLISP

Limitations You Should Know

  • Does not convert 3D polylines to 2D polylines
  • Does not modify block internal geometry
  • Not suitable for:
    • Civil 3D surfaces
    • Revit imports with heavy proxy objects

For strict control, a coordinate rewrite approach (via Visual LISP) is required.


FAQ

Does FLATZ really set all Z values to zero?

No. It forces a recalculation that often removes Z inconsistencies. It does not explicitly rewrite all coordinates.


Why not just use AutoCAD FLATTEN?

The built-in command:

  • Often fails on complex drawings
  • Requires user interaction
  • Can distort geometry

FLATZ is faster and more predictable in messy files.


Is using 1e99 safe?

In most cases, yes. However:

  • Extremely large drawings may experience instability
  • Some AutoCAD versions handle large numbers differently

A safer alternative is using a smaller value like 1e6, with slightly reduced effectiveness.


Can this fix hatch or fillet errors?

Yes, in many cases. Those errors are usually caused by:

  • Slight Z offsets
  • Non-coplanar edges

FLATZ helps normalize those conditions.


Should I use this in production?

Yes, with awareness:

  • Good for cleanup workflows
  • Not a replacement for precision modeling

Does it work with blocks?

It processes block references, but:

  • Internal geometry inside blocks may remain unchanged
  • Exploding blocks may still be required in some cases

What’s the best workflow with FLATZ?

  1. Import drawing
  2. Run FLATZ
  3. Run OVERKILL
  4. Clean layers and purge
  5. Start production

If you want a version that guarantees true Z=0 rewriting, handles 3D polylines, or processes nested blocks, that requires a different approach using Visual LISP and object property editing.