@andreas7ZYXQ hi,
Check this MCSV (Make CSV file) command 😀
TAG1, TAG2 TAG3 (lines 79-81) represent your 3 attributes respectively (e.g "section" "address" & "page")
make sure to synchronize these tags name with the tags name in the block.
command starts with asking you the csv file name to write to than select object(s): pick the blocks to write out attributes. only blocks that has the 3 attributes match, will be taken.
enjoy
Moshe
(vl-load-com) ; load activex support
; Make CSV file
(defun c:mcsv (/ match_attribute alternative3 attributes->list LM:lst->str summarize ; local functions
fname ss f ctr ename AcDbBlkRef AcDbAttrib attributes)
(defun match_attribute (lst tag)
(vl-some
(function
(lambda (attrib)
(if (eq (strcase (vla-get-tagString attrib)) (strcase tag)) attrib)
)
)
lst
); vl-some
); match_attribute
; return list of attributes that match 3 alternative
(defun alternative3 (lst / l)
(if
(vl-every
(function
(lambda (attrib)
(eq (type attrib) 'VLA-OBJECT)
)
); function
(setq l (mapcar
(function
(lambda (tag)
(match_attribute lst tag)
)
); function
(list TAG1 TAG2 TAG3)
); mapcar
); setq
); vl-every
l)
); alternative3
(defun attributes->list (attributes / lst)
(foreach attrib attributes
(setq lst (append lst (list (vla-get-textString attrib))))
)
lst
); attributes->list
;; List to String - Lee Mac
;; 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 LM:lst->str ( lst del )
(if (cdr lst)
(strcat (car lst) del (LM:lst->str (cdr lst) del))
(car lst)
)
); LM:lst->str
(defun summarize ()
(cond
((= ctr 0)
(vlr-beep-reaction)
(princ (strcat "\n0 record(s) written to " fname " file."))
); case
( t
(princ (strcat "\n" (itoa ctr) " record(s) written to " fname " file."))
)
); cond
); summarize
; here start c:mcsv
; declar 3 attributes to seek for
(setq TAG1 "section") ; const
(setq TAG2 "address") ; const
(setq TAG3 "page") ; const
(if (and
(setq fname (getfiled "Save excel csv file" (strcat (getvar "dwgprefix") (vl-string-right-trim ".dwg" (getvar "dwgname"))) "csv" 9))
(setq ss (ssget (list '(0 . "insert") '(66 . 1))))
(setq f (open fname "w"))
)
(progn
(write-line (LM:lst->str (list TAG1 TAG2 TAG3) ",") f) ; header line
(setq ctr 0)
(foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
(setq AcDbBlkRef (vlax-ename->vla-object ename))
(if (setq attributes (alternative3 (vlax-invoke AcDbBlkRef 'GetAttributes)))
(progn
(setq ctr (1+ ctr))
(write-line (LM:lst->str (attributes->list attributes) ",") f)
); progn
); if
; dispose memory
(foreach AcDbAttrib attributes
(vlax-release-object AcDbAttrib)
)
(vlax-release-object AcDbBlkRef) ; dispose memory
); foreach
(setq f (close f)) ; close file
(summarize)
); progn
); if
(princ)
); c:mcsv