Wednesday, March 11, 2026

FREE LISP : Improving Drawing Quality by using Ortho-Check LISP

 

Improving Drawing Quality with an Ortho-Check LISP Tool

In many CAD workflows, especially in architectural, engineering, and construction drawings, maintaining orthogonal geometry (lines that are perfectly horizontal or vertical) is essential. However, during the drafting process, it is very common for small inaccuracies to occur. These errors may be almost invisible on screen but can create serious issues later in design coordination, quantity calculations, and model conversions.

An AutoLISP Ortho-Check tool helps solve this problem by automatically detecting and highlighting lines or polyline segments that are not aligned with the X or Y axis.



Common Problems in CAD Drawings

Even experienced CAD users frequently encounter situations where geometry is slightly misaligned. Some typical causes include:

1. Accidental Ortho Off
When the Ortho mode is turned off during drafting, lines may be drawn at a small angle unintentionally.

2. Snap or Input Precision Issues
Manual coordinate input or object snaps may produce tiny deviations, resulting in lines that appear straight but are actually rotated by a small angle.

3. Imported or Converted Drawings
Drawings imported from other software or converted from formats such as PDF, BIM models, or GIS data often contain geometry that is not perfectly orthogonal.

4. Editing Existing Geometry
Stretching, trimming, or modifying existing elements may introduce small angle deviations.

5. Polyline Segment Errors
Polylines can contain segments that are slightly rotated even when most of the shape is orthogonal.

These issues are often difficult to detect manually, especially in large drawings containing hundreds or thousands of objects.


Risks of Non-Orthogonal Geometry

Small angular errors can cause several downstream problems, including:

  • Dimension inaccuracies

  • Incorrect area or quantity calculations

  • Problems when generating BIM models

  • Difficulty when aligning walls, grids, or structural elements

  • Errors during CNC or fabrication workflows

  • Poor drawing standards and quality control issues

Because of these risks, many organizations implement drawing quality control (QC) procedures before issuing drawings.


How the AutoLISP Ortho-Check Tool Helps

The Ortho-Check AutoLISP tool automates the detection process by performing the following steps:

  1. The user selects lines and polylines in the drawing.

  2. The program analyzes each segment of the geometry.

  3. It compares the X and Y coordinates of endpoints using a tolerance value.

  4. Any segment that is not horizontal or vertical is identified.

  5. The object is automatically highlighted for easy review.

  6. A summary dialog reports the number of checked objects and detected errors.

This process allows users to quickly locate problematic geometry that would otherwise be very difficult to find manually.


Key Benefits

1. Faster Quality Control
Instead of visually inspecting drawings, the tool checks hundreds or thousands of objects in seconds.

2. Improved Drawing Accuracy
It ensures that geometry strictly follows orthogonal design standards.

3. Reduced Risk of Downstream Errors
By identifying geometry issues early, the tool prevents problems in modeling, documentation, and construction.

4. Works with Large Drawings
The AutoLISP solution is lightweight and performs efficiently even with very large datasets.

5. Supports Lines and Polylines
The tool checks both simple lines and complex polyline segments, which are common in architectural and engineering drawings.

6. Easy Integration into QC Workflow
Because the tool runs directly inside AutoCAD, it can easily become part of a standard drawing review procedure.


Practical Use Cases

This tool is particularly useful for:

  • Architectural floor plans

  • Structural grid layouts

  • Infrastructure drawings

  • Shop drawings

  • CAD files converted from BIM models

  • Drawings received from external consultants

In these scenarios, ensuring that geometry is truly orthogonal can significantly improve drawing quality and coordination.


Conclusion

Small geometric inaccuracies are common in CAD drawings, but they can lead to significant problems if left unchecked. An AutoLISP-based Ortho-Check tool provides a simple yet powerful way to automatically detect and highlight non-orthogonal lines and polyline segments.

By incorporating this tool into the drawing review process, CAD teams can improve quality control, reduce errors, and ensure cleaner, more reliable drawings before they are issued for construction or further design development.


Source code

(defun c:QCORTHO (/ ss tol i ent ed typ p1 p2 dx dy pts pt prev flag errss tot err msg)

  (setq tol (getreal "\nSpecify Ortho tolerance <0.0001>: "))
  (if (null tol) (setq tol 0.0001))

  (prompt "\nSelect LINE / POLYLINE to check: ")
  (setq ss (ssget '((0 . "LINE,LWPOLYLINE"))))

  (if ss
    (progn
      (setq i 0)
      (setq tot 0)
      (setq err 0)
      (setq errss (ssadd))

      (while (< i (sslength ss))

        (setq ent (ssname ss i))
        (setq ed (entget ent))
        (setq typ (cdr (assoc 0 ed)))
        (setq flag nil)

        ;; LINE
        (if (= typ "LINE")
          (progn
            (setq p1 (cdr (assoc 10 ed)))
            (setq p2 (cdr (assoc 11 ed)))

            (setq dx (abs (- (car p1) (car p2))))
            (setq dy (abs (- (cadr p1) (cadr p2))))

            (if (and (> dx tol) (> dy tol))
              (setq flag T)
            )
          )
        )

        ;; LWPOLYLINE
        (if (= typ "LWPOLYLINE")
          (progn
            (setq pts '())

            (foreach d ed
              (if (= (car d) 10)
                (setq pts (append pts (list (cdr d))))
              )
            )

            (setq prev nil)

            (foreach pt pts
              (if prev
                (progn
                  (setq dx (abs (- (car prev) (car pt))))
                  (setq dy (abs (- (cadr prev) (cadr pt))))

                  (if (and (> dx tol) (> dy tol))
                    (setq flag T)
                  )
                )
              )
              (setq prev pt)
            )
          )
        )

        ;; mark error
        (if flag
          (progn
            (redraw ent 3)
            (ssadd ent errss)
            (setq err (+ err 1))
          )
        )

        (setq tot (+ tot 1))
        (setq i (+ i 1))
      )

      ;; -------- dialog summary --------
      (setq msg
        (strcat
          "QC ORTHO CHECK RESULT\n\n"
          "Total objects checked : " (itoa tot) "\n"
          "Non-Ortho objects : " (itoa err) "\n\n"
          "Highlighted objects need correction."
        )
      )

      (alert msg)

    )
  )

  (princ)
)


Wednesday, February 25, 2026

FREE LISP : Draw curved stairs with numbering

 

LISP for Architects: Automatically Generating Curved Stairs from an Arc

In architectural drafting, stairs are one of the most common yet repetitive elements to draw. When designing curved stairs, the process can become time-consuming because each step must be carefully distributed along a curved path while maintaining consistent spacing and alignment.

Using LISP, architects and CAD technicians can automate this process and significantly reduce drafting time. This article introduces a simple yet powerful concept: automatically generating a curved stair layout from a selected arc.


The Problem with Manual Drafting

When creating a curved stair manually in PTCAD, the typical workflow involves:

  1. Drawing the center arc of the staircase.

  2. Calculating the angle division for each step.

  3. Drawing radial lines for each riser.

  4. Adding inner and outer boundaries.

  5. Labeling the steps.

For a staircase with 15–20 steps, this can easily take several minutes. In large projects where multiple stairs exist, the time spent becomes significant. In addition, manual work increases the risk of errors such as:

  • Uneven step spacing

  • Incorrect stair width

  • Misaligned riser lines

  • Inconsistent geometry


The LISP Solution

A custom LISP routine can automate the entire process. With a single command, the user simply:

  1. Selects an Arc representing the stair direction.

  2. Inputs the number of steps.

  3. Specifies the inner and outer radius of the stair.

The script then automatically:

  • Divides the arc into equal angular segments

  • Draws riser lines between the inner and outer radius

  • Generates the stair layout instantly

This transforms a multi-step manual process into a few seconds of automated drafting.


How the Algorithm Works

The logic behind the LISP routine is straightforward:

  1. Read the arc geometry:

    • Center point

    • Start angle

    • End angle

  2. Calculate the total arc angle:

Arc Angle=End AngleStart Angle\text{Arc Angle} = \text{End Angle} - \text{Start Angle}
  1. Divide the arc angle by the number of steps:

Step Angle=Arc AngleNumber of Steps\text{Step Angle} = \frac{\text{Arc Angle}}{\text{Number of Steps}}
  1. Generate radial lines using polar coordinates from the arc center.

Each step is positioned by incrementally adding the step angle and projecting points using the polar function.


Example Workflow

An architect designing a curved staircase might follow this process:

  1. Draw the stair center arc.

  2. Run the command:

ARCSTAIR
  1. Select the arc.

  2. Enter the number of steps (e.g., 12).

  3. Input the inner and outer radii.

Within seconds, the stair layout is generated automatically.


Benefits for Architectural Practice

Using LISP for curved stair generation offers several advantages:

1. Speed

Tasks that normally take several minutes can be completed in seconds.

2. Accuracy

Steps are mathematically distributed along the arc, eliminating spacing errors.

3. Consistency

Every staircase in a project follows the same geometric logic.

4. Productivity

Architects and drafters can focus more on design rather than repetitive drafting work.


Typical Stair Design Considerations

When applying this automation tool, architects should still follow common stair design guidelines:

ParameterTypical Range
Riser Height150–180 mm
Tread Depth250–300 mm
Stair Width900–1500 mm

The LISP routine simply assists in drafting the geometry; the designer still controls the parameters.


Expanding the Tool

This basic curved stair generator can be extended further to include:

  • Automatic step numbering

  • Stair UP/DOWN arrows

  • Stair width control

  • Automatic dimension placement

  • Generation of 3D stair geometry

  • Automatic stair schedule export

With these enhancements, LISP can evolve from a simple drafting aid into a powerful architectural productivity tool.


Conclusion

Curved staircases are visually elegant but can be tedious to draft manually. By leveraging LISP automation, architects can transform a repetitive process into a fast and reliable workflow.

A simple script that generates stairs from an arc demonstrates how small automation tools can dramatically improve efficiency in architectural drafting. For firms that frequently work with complex geometry, investing in custom LISP tools can lead to significant gains in both productivity and drawing quality.


Source code

(defun c:CSTAIR ( / ent ed cen rad ang1 ang2 step ang
                    r1 r2 tread i a p1 p2 mid txtpt)
(prompt "\nSelect ARC for stair centerline: ")
(setq ent (car (entsel)))
(setq ed (entget ent))
(if (= (cdr (assoc 0 ed)) "ARC")
(progn
(setq cen (cdr (assoc 10 ed)))
(setq rad (cdr (assoc 40 ed)))
(setq ang1 (cdr (assoc 50 ed)))
(setq ang2 (cdr (assoc 51 ed)))
(setq step (getint "\nEnter number of steps: "))
(setq r1 (getreal "\nInner radius: "))
(setq r2 (getreal "\nOuter radius: "))
(setq ang (/ (- ang2 ang1) step))
(prompt "\nCreating stairs...")
(setq i 0)
(while (<= i step)
(setq a (+ ang1 (* ang i)))
(setq p1 (polar cen a r1))
(setq p2 (polar cen a r2))
(command "LINE" p1 p2 "")
(setq i (+ i 1))
)
(setq i 0)
(while (< i step)
(setq a (+ ang1 (* ang (+ i 0.5))))
(setq mid (polar cen a (/ (+ r1 r2) 2)))
(setq txtpt mid)
(PRINC (ITOA i))
(setq txh (* r1 0.03))
(command "TEXT" txtpt txh 0 (itoa (+ i 1)))
(setq i (+ i 1))
)
(command "ARC" (polar cen ang1 r1) "C" cen (polar cen ang2 r1))
(command "ARC" (polar cen ang1 r2) "C" cen (polar cen ang2 r2))
(setq mid (polar cen (+ ang1 (/ (- ang2 ang1) 2)) r2))
(command "LEADER" mid (polar mid (/ pi 2) 1.0) "" "UP" "")
(prompt "\nCurved stair created successfully.")
)
(prompt "\nSelected object is not ARC.")
)
(princ)
)


Wednesday, February 18, 2026

FREE LISP : Draw Stair Number

Auto Numbering Along a Line in PTCAD (Using LISP)

When working with drawings such as layout grids, parking numbers, seat numbers, column numbering, or coordinate markers, we often need to place numbers evenly spaced along a straight line. Doing this manually can be slow and error-prone.

This simple LISP routine helps automate the process.

What This LISP Does

The command allows the user to:

  1. Specify the number of texts

  2. Define the starting number

  3. Set the text height

  4. Pick a start point and end point

The program will then:

  • Place the first number at the start point

  • Place the last number at the end point

  • Automatically divide the space evenly

  • Insert all numbers in sequence

Example result:

1 ---- 2 ---- 3 ---- 4 ---- 5

All numbers are spaced equally along the selected line.

Why This Is Useful

This tool is especially helpful for tasks such as:

  • Column numbering in structural drawings

  • Parking lot numbering

  • Seat numbering in halls or stadiums

  • Grid labeling

  • Survey or coordinate markers

  • Repetitive annotation tasks

Instead of calculating spacing manually, the LISP automatically divides the distance and places the numbers correctly.

Tips for Best Use

Use Object Snap (OSNAP)
Snap precisely to the intended start and end points.

Use appropriate text height
Choose a height that matches the drawing scale.

Plan the numbering direction
Numbers will increase from the first picked point toward the second point.

Use it with construction lines
You can draw a temporary line as a guide and erase it afterward.

Works in all CAD version support LISP
Because the routine uses standard LISP (no Visual LISP functions).

Productivity Benefit

For example:

Manual work

Place text → copy → move → edit numbers → repeat

Using this LISP

Pick start → pick end → done

                 What might take 2–3 minutes manually can be done in just a few seconds.


Here is VDO Link

https://www.tiktok.com/@ptcaduser/video/7613673564130086160?is_from_webapp=1&sender_device=pc&web_id=7486330426983859719


Below is source code.

Command to run  is NLL


(defun c:NLL (/ p1 p2 n startnum hgt i dx dy px py)
  (setq n (getint "\nNumber of texts: "))
  (setq startnum (getint "\nStarting number: "))
  (setq hgt (getreal "\nText height: "))
  (setq p1 (getpoint "\nPick start point of line: "))
  (setq p2 (getpoint p1 "\nPick end point of line: "))
  (setq dx (/ (- (car p2) (car p1)) (- n 1)))
  (setq dy (/ (- (cadr p2) (cadr p1)) (- n 1)))
  (setq i 0)
  (while (< i n)
    (setq px (+ (car p1) (* i dx)))
    (setq py (+ (cadr p1) (* i dy)))
    (command "TEXT" (list px py) hgt "0" (itoa (+ startnum i)))
    (setq i (+ i 1))
  )
  (princ)
)




Wednesday, January 14, 2026

FREE LISP : Draw text on pick point

           In drafting work, sometimes users need to label the coordinates of multiple selected points at the same time. Normally, they have to use the text command and write the coordinates one point at a time.

Currently, AI can be used to help generate code to create a new command. We will try using AI to write a command that reads the coordinates of selected points and automatically labels the coordinates for multiple selected points simultaneously as follows.




Source code

(defun c:coords ( / pt oldos txtsize coll )
  (setq oldos (getvar "OSMODE"))
  (setvar "OSMODE" 0)

  (setq txtsize 0.075)
  (setq coll (getvar "cecolor"))   ;; current color


  (prompt "\nClick points to write coordinates. Press SPACE or ENTER to finish.\n")

  (while (setq pt (getpoint "\nSelect point: "))
(command "color" "4")   ;; set color as cyan
    (command "TEXT"
             pt
             txtsize
             0
             (strcat
               (rtos (car pt) 2 2)
               ","
               (rtos (cadr pt) 2 2)
             )
    )   (command "setvar" "cecolor" coll)   ;; return current color
  )

  (setvar "OSMODE" oldos)
  (princ)
)

FREE LISP : Improving Drawing Quality by using Ortho-Check LISP

  Improving Drawing Quality with an Ortho-Check LISP Tool In many CAD workflows, especially in architectural, engineering, and construction...