Hi again
How about this routine?
Thank you
f.
Code:
; Convert list to string with delimeter ;
(defun strfil (lst)
(setq strk "")
(while lst
(setq tmp (strcat (car lst) ","))
(setq strk (strcat strk tmp )
lst (cdr lst)))
(vl-string-right-trim "," strk))
;; Groups elements in list by test
(defun tracks (test lst)
(apply 'append (mapcar '(lambda (x)
(if (wcmatch x test)(list x ))) lst)))
;;;(setq a (vlax-ename->vla-object (car (entsel))))
(defun C:CountPlants (/ acsp adoc cl
cn cnt count_list data_table
header hgt lgh patt
snip sub_header tbl_obj tmp_count
total_summ tot_row tpt txt_list
type_list
)
(vl-load-com)
(setq adoc (vla-get-activedocument
(vlax-get-acad-object)
)
acsp (vla-get-block
(vla-get-activelayout adoc)
)
)
(setq type_list '("AR" "JH" "JHR");change by suit
type_list (mapcar (function (lambda (x)
(strcat "*" x)
)
)
type_list
)
)
(vlax-for a acsp
(if (and (wcmatch (vla-get-objectname a) "AcDbText,AcDbMText")
(wcmatch (vla-get-textstring a) (strfil type_list))
)
(setq txt_list (cons (vla-get-textstring a) txt_list))
)
)
(repeat (length type_list)
(setq patt (car type_list))
(setq snip (tracks patt txt_list))
(setq tmp_count (list (car snip) (itoa (length snip))))
(setq count_list (cons tmp_count count_list))
(setq type_list (cdr type_list))
)
(setq count_list (reverse count_list))
(setq total_summ
(itoa (apply '+ (mapcar 'atoi (mapcar 'cadr count_list)))
)
)
(setq cnt 1)
(foreach i count_list
(setq i (append (list (itoa cnt)) i))
(setq data_table (cons i data_table))
(setq cnt (1+ cnt))
)
(setq data_table (reverse data_table))
(setq tot_row (list "Total" "-" total_summ));change by suit
(setq data_table (append data_table (list tot_row)))
(setq header (getstring t "\n Table Header Text:\n"))
(initget 1)
(setq tpt (getpoint "\nTable Insertion Point: \n"))
(initget 1)
(setq hgt (getdist "\nRow Height: \n"))
(initget 1)
(setq lgh (getdist "\nColumn Length: \n"))
(setq sub_header '("##" "Plant Label" "Quantity"));change by suit
(setq tbl_obj (vla-addtable
acsp
(vlax-3d-point tpt)
(+ (length data_table) 2)
(length sub_header)
hgt
lgh
)
)
(vla-settext tbl_obj 0 0 header)
(vla-setcellalignment tbl_obj 0 0 acmiddlecenter)
(vla-setcelltextheight tbl_obj 0 0 250.);header text height-change by suit
(setq cn 0)
(foreach item sub_header
(vla-settext tbl_obj 1 cn item)
(vla-setcellalignment tbl_obj 1 cn acmiddlecenter)
(vla-setcelltextheight tbl_obj 1 cn 225.);sub_header text height-change by suit
(setq cn (1+ cn))
)
(setq cl 2)
(setq cn 0)
(foreach a data_table
(foreach b a
(vla-settext tbl_obj cl cn b)
(vla-setcellalignment tbl_obj cl cn acmiddlecenter)
(vla-setcelltextheight tbl_obj cl cn 200.);cell text height-change by suit
(setq cn (1+ cn))
)
(setq cl (1+ cl))
(setq cn 0)
)
(princ)
)
(C:CountPlants)
(princ)