Using ChatGPT to Write AutoLISP Routines for AutoCAD and Civil 3D

September 23, 2026 Nick Turner

Title:

Using ChatGPT to Write AutoLISP Routines for AutoCAD and Civil 3D

Applies To

  • AutoCAD
  • Civil 3D
  • AutoLISP / Visual LISP
  • ChatGPT

Issue

AutoCAD and Civil 3D contain thousands of commands and tools, but there are still many repetitive tasks that require several steps or do not have a built-in command that performs exactly what a user needs.

AutoLISP has long been one of the best ways to automate these tasks. The challenge is that many AutoCAD and Civil 3D users do not have programming experience and may not know how to write or troubleshoot a LISP routine.

ChatGPT can help bridge that gap by allowing users to describe what they want the routine to accomplish in plain language and then generate AutoLISP code that can be tested in AutoCAD or Civil 3D.

Causes

Many CAD workflows involve repetitive processes that are good candidates for automation. Examples include:

  • Selecting and modifying multiple objects.
  • Creating or changing layers.
  • Extracting object information.
  • Placing labels or blocks based on drawing information.
  • Performing calculations from selected geometry.
  • Automating repetitive drafting standards.
  • Reading Civil 3D object properties.
  • Creating custom commands for workflows that otherwise require several manual steps.

Traditionally, creating these tools required knowledge of AutoLISP syntax, AutoCAD object types, system variables, selection sets, ActiveX/Visual LISP functions, and sometimes the Civil 3D API.

ChatGPT can assist with much of the initial code development while also helping troubleshoot and refine the routine.

Solution

ChatGPT can be used to generate an AutoLISP routine by describing the desired workflow as specifically as possible.

For example, instead of asking:

Write a LISP for slopes.

Provide ChatGPT with the actual workflow:

Write an AutoLISP routine for Civil 3D that allows me to select a TIN surface, pick multiple locations on the surface, calculate the slope at each location, and place an arrow pointing in the downhill direction with the percent slope displayed next to the arrow.

The additional information gives ChatGPT much more context about the desired result.

1. Describe the Workflow

Start by explaining what you currently do manually.

Include information such as:

  • What objects will be selected?
  • Is this AutoCAD or Civil 3D?
  • What should the command create?
  • Should existing objects be modified?
  • What information should be displayed?
  • Should the routine process one object or multiple objects?
  • Should the user select objects or should the routine find them automatically?

The more specific the description, the better the initial routine will usually be.

2. Ask ChatGPT to Create a Command Name

Have ChatGPT create a simple command that can be entered at the AutoCAD command line.

For example: SURFSLOPE

Copy the tet from ChatGPT to a Notepad document and Save as .lsp

The routine can then be loaded by typing APPLOAD into the Command Line and selecting the file.

After loading the .LSP file, enter the new command name at the AutoCAD or Civil 3D command line.

3. Test the Routine on a Copy of the Drawing

AI-generated code should always be tested before using it on production drawings.

Use a test drawing or a copy of the project drawing and verify:

  • The correct objects are selected.
  • The calculations are correct.
  • Objects are placed on the expected layers.
  • Existing drawing objects are not unintentionally modified.
  • The routine handles invalid selections.
  • The routine works correctly when the user presses ESC or Enter.
  • Civil 3D objects remain intact.

This is particularly important when a routine modifies or deletes existing objects.

4. Use Error Messages to Improve the LISP

The first version of a routine may not always work correctly.

If AutoCAD displays an error such as:

error: no function definition

or:

error: bad argument type

copy the exact error message into ChatGPT.

Also explain what you were doing when the error occurred.

For example:

The routine loads successfully. I select my Civil 3D surface and pick a location. After picking the location, I receive "error: bad argument type: numberp: nil."

This information can help ChatGPT identify which portion of the code needs to be corrected.

Screenshots of the AutoCAD command line can also be useful when troubleshooting.

5. Refine the Routine

Once the basic command works, additional functionality can be added.

For example, a simple slope routine could later be modified to:

  • Process multiple points.
  • Automatically create slope arrows across a grid.
  • Allow the user to specify arrow spacing.
  • Place objects on a predefined layer.
  • Use a specific text style.
  • Display slope as percent, decimal grade, or ratio.
  • Skip locations outside the surface.
  • Limit processing to a selected boundary.
  • Create a legend.
  • Remember settings from the previous run.

It is often easier to get a simple version working first and then add features one at a time.

Important Considerations

ChatGPT should be treated as a development assistant rather than assuming every generated routine is ready for production use.

AutoLISP routines can interact directly with drawing objects, system variables, files, and AutoCAD settings. A poorly written routine could modify or delete objects unexpectedly.

Always:

  • Save the drawing before testing.
  • Test new routines on non-production files.
  • Review what the routine is designed to change.
  • Keep backup copies of important drawings.
  • Test the routine in the AutoCAD/Civil 3D versions where it will actually be used.

Also keep in mind that standard AutoCAD objects and Civil 3D objects are not the same. A routine that works with lines, polylines, blocks, and text may be relatively straightforward, while accessing surfaces, alignments, profiles, corridors, pipe networks, or other Civil 3D objects may require Visual LISP/ActiveX functions or Civil 3D-specific APIs.

Example Uses

Some practical AutoLISP routines that can be developed with assistance from ChatGPT include:

  • Reporting elevations from a Civil 3D surface.
  • Creating slope-direction arrows on a surface.
  • Finding objects on incorrect layers.
  • Batch-changing object properties.
  • Creating layers automatically.
  • Renaming blocks.
  • Extracting block attributes.
  • Calculating slopes between selected points.
  • Finding duplicate objects.
  • Automating drawing cleanup.
  • Placing standardized notes or symbols.
  • Checking drawing standards.
  • Automating repetitive plotting or sheet preparation tasks.

Conclusion

You do not have to be an experienced programmer to begin creating useful AutoLISP routines.

If you understand the CAD workflow and can clearly describe the steps you want to automate, ChatGPT can help turn those requirements into AutoLISP code, explain how the code works, troubleshoot errors, and progressively add functionality.

The best approach is to start with a small repetitive task, clearly describe the desired workflow, generate a basic routine, and test it carefully. Once the initial routine is working, it can be refined into a customized tool that may turn a multi-step CAD process into a single command.

 

Previous Article
Civil 3D Data Shortcuts Not Working Correctly in a Forma Project

Next Article
AutoCAD and AutoCAD Verticals 2025 Exception and Fatal Error
AutoCAD and AutoCAD Verticals 2025 Exception and Fatal Error

AutoCAD and AutoCAD based products crash after installing Vault update.

×

Get Tips Delivered.

Subscribe to Email Updates.

First Name
Last Name
Country
Thank you!
Error - something went wrong!