CADLisp Tools

Data Extraction

Export Block Attributes to CSV AutoLISP routine

Export selected block names and attribute tag/value pairs to a CSV file. Download the .LSP source below and run the ATTCSV command after loading it.

⌘ ATTCSVv1.0.0AdvancedUpdated Sep 18, 2026

What it does

Export Block Attributes to CSV with the ATTCSV AutoLISP command

Writes one row per selected attributed block, including its handle, block name, and a semicolon-delimited attribute summary for review outside CAD.

AutoLISP command
ATTCSV
Difficulty
Advanced

Applicable disciplines

CAD workflows that use this routine

Requirements and compatibility

What it needs

AutoLISPVisual LISPActiveX

Software rows marked “Not tested” are not compatibility claims. Test the routine in a copy of your drawing and CAD version.

Downloadable source code

Review the export-block-attributes-csv.lsp AutoLISP code

export-block-attributes-csv.lspAUTOLISP
;; CADLisp Tools - Export Block Attributes to CSV
(vl-load-com)

(defun ct-ac:replace-all (text find replacement / position start)
  (setq start 0)
  (while (setq position (vl-string-search find text start))
    (setq text (strcat (substr text 1 position) replacement
                       (substr text (+ position (strlen find) 1)))
          start (+ position (strlen replacement))))
  text)

(defun ct-ac:csv (value)
  (if (null value) (setq value ""))
  (setq value (ct-ac:replace-all value "\r" " ")
        value (ct-ac:replace-all value "\n" " ")
        value (ct-ac:replace-all value "\"" "\"\""))
  (strcat "\"" value "\""))

(defun ct-ac:invoke-list (obj method / result)
  (setq result (vl-catch-all-apply 'vlax-invoke (list obj method)))
  (if (vl-catch-all-error-p result) nil result))

(defun ct-ac:attributes (obj)
  (append (ct-ac:invoke-list obj 'GetAttributes)
          (ct-ac:invoke-list obj 'GetConstantAttributes)))

(defun ct-ac:property (object getter / result)
  (setq result (vl-catch-all-apply getter (list object)))
  (if (vl-catch-all-error-p result) nil result))

(defun ct-ac:block-name (obj / result)
  (if (vlax-property-available-p obj 'EffectiveName)
    (setq result (ct-ac:property obj 'vla-get-EffectiveName)))
  (if (null result) (setq result (ct-ac:property obj 'vla-get-Name)))
  result)

(defun c:ATTCSV (/ *error* answer att attrs ent file handle i item name obj path
                   rows skipped ss summary tag value)
  (defun *error* (message)
    (if file (progn (close file) (setq file nil)))
    (if (and message (not (wcmatch (strcase message) "*CANCEL*,*QUIT*,*EXIT*")))
      (prompt (strcat "\nATTCSV error; a partial file may remain: " message)))
    (princ))
  (prompt "\nSelect attributed blocks: ")
  (if (setq ss (ssget '((0 . "INSERT"))))
    (if (setq path (getfiled "Save attribute CSV" "block-attributes.csv" "csv" 1))
      (progn
        (if (findfile path)
          (progn
            (initget "Yes No")
            (setq answer (getkword "\nFile exists. Overwrite it? [Yes/No] <No>: "))))
        (if (or (null (findfile path)) (= answer "Yes"))
          (progn
            (setq file (vl-catch-all-apply 'open (list path "w")))
            (if (vl-catch-all-error-p file) (setq file nil))
            (if file
              (progn
                (write-line "Handle,Block,Attributes" file)
                (setq i 0 rows 0 skipped 0)
                (repeat (sslength ss)
                  (setq ent (ssname ss i)
                        obj (and ent (vl-catch-all-apply 'vlax-ename->vla-object (list ent)))
                        summary "")
                  (if (and obj (not (vl-catch-all-error-p obj)))
                    (progn
                      (setq attrs (ct-ac:attributes obj))
                      (foreach item attrs
                        (setq tag (ct-ac:property item 'vla-get-TagString)
                              value (ct-ac:property item 'vla-get-TextString))
                        (if tag
                          (setq summary (strcat summary (if (= summary "") "" "; ")
                                                tag "=" (if value value "")))))
                      (setq handle (ct-ac:property obj 'vla-get-Handle)
                            name (ct-ac:block-name obj))
                      (if (and handle name)
                        (progn
                          (write-line (strcat (ct-ac:csv handle) "," (ct-ac:csv name) ","
                                              (ct-ac:csv summary)) file)
                          (setq rows (1+ rows)))
                        (setq skipped (1+ skipped))))
                    (setq skipped (1+ skipped)))
                  (setq i (1+ i)))
                (close file)
                (setq file nil)
                (prompt (strcat "\nCSV saved: " path " (" (itoa rows)
                                " row(s), " (itoa skipped) " skipped).")))
              (prompt "\nThe file could not be opened for writing.")))
          (prompt "\nExport cancelled; the existing file was not changed.")))
      (prompt "\nExport cancelled."))
    (prompt "\nNo attributed blocks selected."))
  (princ))

Setup

How to install the export-block-attributes-csv.lsp file

  1. 1Download and review the source code.
  2. 2Load the .lsp file with APPLOAD in a copy of a drawing.
  3. 3Keep the routine session-only until it has been tested for your CAD version and standards.

Command workflow

How to run the ATTCSV command

  1. 1Run ATTCSV.
  2. 2Select attributed block references.
  3. 3Choose a CSV filename and save.

Worked example

Example: Export equipment attributes for spreadsheet review.

  1. Run ATTCSV.
  2. Select equipment blocks.
  3. Save equipment.csv.
Expected result

The CSV contains one block row with its attribute summary.

Read before use

Notes and limitations

  • Requires ActiveX attribute access and local file write permission.
  • Uses one summary column rather than one column per unique tag.
  • Not manually CAD-tested.

Version history

Changelog

v1.0.0Sep 18, 2026Initial quoted-CSV export routine.

Keep automating

Related tools

Data Extraction4 disciplines

BOM from Block Attributes

Count selected blocks by one chosen attribute value.

⌘ BLOCKBOMAdvancedCAD support: not tested
Updated Sep 18, 2026VIEW TOOL →
Blocks & Attributes6 disciplines

Count Selected Blocks

Summarize selected block references by name in the command line.

⌘ COUNTBLOCKSIntermediateCAD support: not tested
Updated Sep 18, 2026VIEW TOOL →
Blocks & Attributes4 disciplines

Equipment Tag Numbering

Write a prefix and sequential number into a chosen block attribute.

⌘ EQTAGNOAdvancedCAD support: not tested
Updated Sep 18, 2026VIEW TOOL →