(defun c:EXPORTBLOCKATTR (/ filename filehandle ss block entity inspt attribs attlst blockname) ;; Set the block name to filter (setq blockname "Mast_eprs_2025_V1") ;; Prompt the user for the CSV file location (setq filename (getfiled "Select Output CSV File" "blocks.csv" "csv" 1)) (if filename (progn ;; Open the file for writing (setq filehandle (open filename "w")) ;; Write the CSV header (write-line "Block Name,X Coordinate,Y Coordinate,Z Coordinate,Attributes" filehandle) ;; Build the selection filter for the specified block name (setq filter (list '(0 . "INSERT") (cons 2 blockname))) ;; Select block references based on the filter (setq ss (ssget "X" filter)) (if ss (progn ;; Iterate through the selection set (repeat (setq i (sslength ss)) (setq block (ssname ss (setq i (1- i)))) ; Get the block reference (setq entity (entget block)) ; Get the block entity data (setq inspt (cdr (assoc 10 entity))) ; Get the insertion point (setq attribs "") ; Initialize attributes string ;; Get the block's attributes (if (setq attlst (vl-remove-if-not '(lambda (x) (= (car x) 70)) (entget block) ) ) (foreach att attlst (setq attribs (strcat attribs (if (> (strlen attribs) 0) ", " "") ; Add a comma if not the first attribute (cdr (assoc 1 (entget att))) ; Get attribute value ) ) ) ) ;; Write the block data to the file (write-line (strcat blockname "," ; Block name (rtos (car inspt) 2 6) "," ; X coordinate (rtos (cadr inspt) 2 6) "," ; Y coordinate (rtos (caddr inspt) 2 6) "," ; Z coordinate "\"" attribs "\"" ; Attributes (quoted) ) filehandle ) ) (princ (strcat "\nExported " (itoa (sslength ss)) " blocks to: " filename)) ) (princ (strcat "\nNo blocks named " blockname " found in the drawing.")) ) ;; Close the file (close filehandle) ) (princ "\nNo file selected.") ) (princ) ; Exit cleanly )