πŸ€– Automate Mesh to Solid Conversion in AutoCAD with AutoLISP

Automate Mesh to Solid Conversion in AutoCAD with AutoLISP

Running AmConvertMesh manually on one imported mesh at a time works for occasional conversions, but any workflow that regularly receives mesh files from external sources - scan data, STL archives, OBJ exports from modeling tools - benefits from automating the sequence. Automesher Application exposes its commands (AmImportMesh, AmConvertMesh, AmExportMesh) to AutoLISP, enabling complete import-convert-export pipelines to run unattended from a script.

This tutorial provides a complete working AutoLISP script that imports an OBJ mesh, converts it to a 3D solid, and exports the result to SKP - and explains every parameter so you can adapt it to your own workflows.

Why Automate with AutoLISP

Manual mesh-to-solid conversion in AutoCAD requires: opening the file, running AmImportMesh, selecting the entity type, running AmConvertMesh, selecting entities, choosing the solid option, enabling Fill Holes and Fix Geometry, and optionally running AmExportMesh. That is 5–8 command interactions per file. For a workflow that processes 50 scan files weekly, automation eliminates hundreds of manual steps and ensures consistent settings every time.

AutoLISP scripts that call Automesher commands can be triggered from:

  • The AutoCAD command line (load and run directly)
  • AutoCAD startup script (run automatically when a drawing opens)
  • A button on a custom ribbon panel or toolbar
  • An external batch process that opens drawings, runs the script, and saves the result

Complete AutoLISP Script: Import, Convert, Export

The following script imports an OBJ mesh file, converts the resulting polyface mesh to a 3D solid with Fill Holes enabled, and exports the solid to SKP:

; Automate mesh-to-solid conversion using Automesher Application
; Requires Automesher Application to be installed and loaded in AutoCAD

(defun c:MeshToSolid ()

  ; Step 1: Disable command dialog boxes so the script runs without popups
  (command "CMDDIA" 0)

  ; Step 2: Import mesh file as polyface mesh
  ; Syntax: AmImportMesh "filepath" "entitytype"
  ; Entity type options: "polyfacemesh" | "3dsolid" | "subdmesh" | "3dface"
  (command "AmImportMesh" "C:\\work\\mesh.obj" "polyfacemesh")

  ; Step 3: Convert the imported polyface mesh to 3D solid
  ; Syntax: AmConvertMesh selection "" "outputtype" "repair" "fillholes" "fixgeometry" "delete"
  ; - (entlast) selects the most recently added entity
  ; - "" ends the selection set
  ; - "3dSolid" specifies 3D ACIS solid output
  ; - "None" = no additional geometry operation after conversion
  ; - "No" = do not delete original mesh after conversion
  ; - "Yes" = enable Fill Holes (patches open boundary loops)
  ; - "Yes" = enable Fix Geometry (repairs non-manifold edges)
  (command "AmConvertMesh" (entlast) "" "3dSolid" "None" "No" "Yes" "Yes")

  ; Step 4: Export the resulting 3D solid to SKP format
  ; Syntax: AmExportMesh selection "" "filepath"
  ; File extension in the path determines the output format
  (command "AmExportMesh" (entlast) "" "C:\\work\\solid.skp")

  ; Step 5: Re-enable command dialog boxes for normal AutoCAD use
  (command "CMDDIA" 1)

  (princ "\nMesh to solid conversion complete.")
  (princ)
)

Load this script in AutoCAD with (load "C:\\path\\to\\MeshToSolid.lsp") then run it by typing MeshToSolid at the command line.

Command Parameter Reference

AmImportMesh Parameters

Parameter Value Notes
File path"C:\\work\\mesh.obj"Full path to the input file; use double backslashes in AutoLISP strings
Entity type"polyfacemesh"Options: "polyfacemesh", "3dsolid", "subdmesh", "3dface" - use polyfacemesh for lightweight import before AmConvertMesh

AmConvertMesh Parameters

Parameter Example Value Notes
Entity selection(entlast)Most recently added entity; use (ssget) for interactive selection or (ssget "X" '((0 . "MESH"))) to select all meshes
Selection end""Empty string signals end of selection set
Output type"3dSolid"Options: "3dSolid", "polyfacemesh", "polygonmesh", "subdmesh", "3dface"
Operation"None"Post-conversion operation; "None" for direct conversion
Delete original"No""Yes" to delete the source mesh after conversion; "No" to keep both
Fill Holes"Yes""Yes" to patch open boundary loops before solid conversion - recommended for imported meshes
Fix Geometry"Yes""Yes" to repair non-manifold edges and reversed normals - recommended for imported meshes

AmExportMesh Parameters

Parameter Example Value Notes
Entity selection(entlast)The entity to export; use selection sets for multiple entities
Selection end""Empty string signals end of selection
Output file path"C:\\work\\solid.skp"The file extension determines the output format - .skp, .stl, .obj, .fbx, .step, etc.

Practical Script Variants

Convert All Polyface Meshes in the Drawing to Solid

(defun c:ConvertAllMeshes ()
  (command "CMDDIA" 0)
  ; Select all polyface mesh entities in the drawing
  (setq ss (ssget "X" '((0 . "POLYFACE MESH"))))
  (if ss
    (progn
      (command "AmConvertMesh" ss "" "3dSolid" "None" "No" "Yes" "Yes")
      (princ (strcat "\nConverted " (itoa (sslength ss)) " mesh entities to 3D solid."))
    )
    (princ "\nNo polyface mesh entities found in drawing.")
  )
  (command "CMDDIA" 1)
  (princ)
)

Import STL and Export to FBX in One Step

(defun c:StlToFbx (stlpath fbxpath)
  (command "CMDDIA" 0)
  (command "AmImportMesh" stlpath "polyfacemesh")
  (command "AmExportMesh" (entlast) "" fbxpath)
  (command "CMDDIA" 1)
  (princ)
)
; Usage: (StlToFbx "C:\\input\\scan.stl" "C:\\output\\scan.fbx")

Frequently Asked Questions

Why does my script fail with "Unknown command: AmConvertMesh"?

Automesher Application must be installed and loaded in AutoCAD before its commands are available to AutoLISP. Verify that Automesher is installed and that AutoCAD has been restarted after installation. Check that the Automesher ribbon tab or toolbar is visible - if it is, the commands are loaded and available to scripts.

Can these scripts run in BricsCAD or ZWCAD?

Yes. BricsCAD supports AutoLISP natively; ZWCAD also supports AutoLISP. The Automesher commands (AmImportMesh, AmConvertMesh, AmExportMesh) work identically in AutoCAD, BricsCAD, ZWCAD, and GstarCAD. Use the same script syntax - only the CMDDIA variable name may differ slightly in some non-AutoCAD platforms.

How do I verify the solid conversion succeeded?

Add a MASSPROP check after conversion: (command "MASSPROP" (entlast) ""). A valid 3D solid returns non-zero volume. You can capture the result programmatically using vl-cmdf or check entity type with (cdr (assoc 0 (entget (entlast)))) - a successful solid conversion returns "3DSOLID".

Summary

Automesher Application exposes AmImportMesh, AmConvertMesh, and AmExportMesh to AutoLISP, enabling complete import-convert-export pipelines to run unattended in AutoCAD, BricsCAD, ZWCAD, and GstarCAD. Set CMDDIA to 0 at the start and 1 at the end of the script to suppress dialog interruptions. Enable Fill Holes and Fix Geometry parameters in AmConvertMesh for imported meshes from external sources. The file extension in the AmExportMesh path determines the output format - .skp, .stl, .obj, .fbx, .step, or any other supported format.

πŸ‘‰ Ready to automate? Download Automesher Application and try it free.