Here is my set of routines, I may have missed including some helper routines. I use it with a reactor to automatically export my symbol and ight fixture blocks and then I have an excel spreadsheet that reads the data files to create schedules. An example export is attached.
(defun c:SAA_ExportKeynoteValues ()
(SAA_ExportKeynoteValues
(list
"#" "DOOR" "DTL" "E" "FLR1" "FUNCTION" "GLAZING" "KEYNOTE" "LOCATION" "MATERIAL"
"MAT1" "MAT2" "MOD" "MOD1" "MOD2" "MODIFIER" "NOTES" "NUMBER" "SHT" "TYPE"
"WIN" "WT" "WIDTH" "x" "HEIGHT"
) ;_list
) ;_SAA
(princ)
)
(defun SAA_ExportKeynoteValues (tagList / tagList ss i aList csvfilename)
(if (setq ss (ssget "X" '((0 . "INSERT")
(-4 . "<OR")
(-4 . "<AND")(2 . "sym*") (8 . "A-Anno*") (-4 . "AND>")
(-4 . "<AND")(2 . "p-light*")(8 . "A-Clng-Lfix")(-4 . "AND>")
(-4 . "OR>")
(66 . 1) ;66 filters for blocks with attributes (assumed meaning?)
))
) ;_ssget
(progn
;; create header (in reverse order of txt export file)
(setq aList (list "EXPORTDATE" "BLOCKNAME" "HANDLE" ))
(foreach tag tagList (setq aList (cons tag aList)))
(setq aList (list (SAA_List2String (reverse aList) "\t")))
;; cycle through blocks and create list of attribute values
(repeat (setq i (sslength ss))
(setq aList (cons
(SAA_List2String
(SAA_getKeynoteAttributeValues
(vlax-ename->vla-object (ssname ss (setq i (1- i))))
tagList
) ;_SAA
"\t"
) ;_SAA_List2String
aList
) ;_list
) ;_setq
) ;_repeat
(setq aList (reverse aList))
;; write list to file
(SAA_WriteList2File alist (setq csvfilename (strcat (getvar "dwgprefix")(vl-filename-base (getvar "dwgname")) "_queryExport.txt")))
(princ (strcat "\n" (vl-filename-base (getvar "dwgname")) "_queryExport.txt - values exported"))
(saa_debugPrinc (strcat " to: " (strcat csvfilename)))
) ;_progn
) ;_if
(princ)
)
;;;==============================================================================
;;; List to String - by Lee Mac (renamed)
;;; Concatenates each string in a supplied list, separated by a given delimiter
;;; lst - [lst] List of strings to concatenate
;;; del - [str] Delimiter string to separate each item
;;;==============================================================================
(defun SAA_List2String ( lst del )
(if (cdr lst)
(strcat (car lst) del (SAA_List2String (cdr lst) del))
(car lst)
)
)
;;;------------------------------------------------------------;;
;;; get block attributes based on order of attribute list provided
;;; blk - [vla] VLA Block Reference Object
;;; attList - list of string names for atributes
;;; return example: ("'10CE39" "sym-keynote02" "11.4" "Qty (2)" "NIL")
;;; Inspired by Lee-Mac routines
;;;------------------------------------------------------------;;
(defun SAA_getKeynoteAttributeValues ( blk attList / varPrefix aList attValue)
(setq varPrefix "SAA_getKeynoteAttributeValues_")
;; cycle through block attributes to save list of values
(mapcar
'(lambda ( att )
(if (member (vla-get-tagstring att) attList)
;; save attribute value to temporary variable name
;; will be part of a list in order of passed in attribute list
(set (read (strcat varPrefix (vla-get-tagstring att))) (vla-get-textstring att))
) ;_if
) ;_lambda
(vlax-invoke blk 'getattributes)
) ;_mapcar
;; create list initial data - uses standard header format of "HANDLE" "BLOCKNAME" "EXPORTDATE"
;; defined in SAA_ExportKeynoteValues lisp
(setq alist
(list
(strcat "'" (vla-get-Handle blk)) ;block handle
(vla-get-effectivename blk) ;block name
(menucmd "M=$(edtime, $(getvar, date),MO.dd.YY HH:MM)") ;date & time of export
) ;_list
)
;; cycle through passed in list of attribute values
;; create a list of block data & attribute values
;; matching format of ATTEXT row data
(foreach att attList
(setq attValue (read (strcat varPrefix att)))
(if (eval attValue)
(setq aList (append aList (list (eval attValue)))
attValue nil ;clear variable
) ;_setq
(setq aList (append aList (list "nil"))
) ;_setq
)
) ;_foreach
;; cycle through and clear passed in list of attribute values
;; as the temp variables are saved as global
(foreach att attList
(set (read (strcat varPrefix att)) nil)
) ;_foreach
aList
;;;==========================================================
;;; Write List to File
;;; write each list item to separate line
;;;==========================================================
(defun SAA_WriteList2File ( lst fname / out_file )
(if (setq out_file (open fname "w"))
(progn
(foreach row lst (princ (strcat row "\n") out_file))
(close out_file)
T
)
)
)
borica_rcp_queryExport.txt