Welcome on board, radosak
Here is quick code example to group your formatted mtexts
(just accordingly to your drawing)
Select all mtexts by window then see a result
Other than that you need to make by yoursef
Code:
(defun C:GPS(/ all dirty en _group_and_sum i ip item lb p1 p2 ss st string->list summary tmp TTC_MText_Clear uniques x)
;; helpers
;; by Tony Tanzillo ;;
(defun string->list (s delim)
(read
(vl-list->string
(append
'(40 34) ;; add '("' to start
(apply 'append
(subst
'(34 34)
(vl-string->list delim)
(mapcar 'list (vl-string->list s))
)
)
'(34 41) ;; add '")" to end
)
)
)
)
;; Cleat MTEXT formatting ;;
;; by VVA ;;
(defun TTC_MText_Clear(Mtext / Text Str)
(setq Text "")
(while(/= Mtext "")
(cond
((wcmatch
(strcase
(setq Str
(substr Mtext 1 2)))
"\\[\\{}`~]")
(setq Mtext(substr Mtext 3)
Text(strcat Text Str)
); end setq
); end condition #1
((wcmatch(substr Mtext 1 1) "[{}]")
(setq Mtext
(substr Mtext 2))
); end condition #2
(
(and
(wcmatch
(strcase
(substr Mtext 1 2)) "\\P")
(/=(substr Mtext 3 1) " ")
); end and
(setq Mtext (substr Mtext 3)
Text (strcat Text " ")
); end setq
); end condition #3
((wcmatch
(strcase
(substr Mtext 1 2)) "\\[LOP]")
(setq Mtext(substr Mtext 3))
); end condition #4
((wcmatch
(strcase
(substr Mtext 1 2)) "\\[ACFHQTW]")
(setq Mtext
(substr Mtext
(+ 2
(vl-string-search ";" Mtext))))
); end condition #5
((wcmatch
(strcase (substr Mtext 1 2)) "\\S")
(setq Str(substr Mtext 3 (- (vl-string-search ";" Mtext) 2))
Text(strcat Text (vl-string-translate "#^\\" " " Str))
Mtext(substr Mtext (+ 4 (strlen Str)))
); end setq
(print Str)
); end condition #6
(T
(setq Text(strcat Text(substr Mtext 1 1))
Mtext (substr Mtext 2)
)
); end condition #7
); end cond
); end while
Text
); end of TTC_MText_Clear
;; fixo () 2010 * all rights released ;;
;; arguments: lst - list of pairs kind of:
;;(setq lst '(("a" . 12)("b" . 12)("a" . 26) ("d" . 23)("b" . 20)("a" . 24) ("c" . 12)("d" . 27)))..etc...;;
(defun _group_and_sum (lst / all i lb summary tmp uniques)
(setq all (mapcar 'car lst)
uniques nil
) ;_ end of setq
(while (car all)
(setq uniques (cons (car all) uniques))
(setq all (vl-remove-if '(lambda (x) (eq x (car all))) all))
) ;_ end of while
(setq i -1
tmp nil
) ;_ end of setq
(repeat (length uniques)
(setq tmp
(cons
(setq lb (nth (setq i (1+ i)) uniques))
(apply '+
(mapcar
'cdr
(vl-remove-if-not '(lambda (x) (eq (car x) lb)) lst)
) ;_ end of mapcar
) ;_ end of apply
) ;_ end of cons
) ;_ end of setq
(setq summary (cons tmp summary))
) ;_ end of repeat
(vl-sort summary '(lambda (a b) (< (car a) (car b))))
) ;_ end of defun
;; Usage :(_group_and_sum lst) ;;
;; main part ;;
(princ "\Select table text by window selection")
(setq p1 (getpoint "\nSpecify the first corner point: >> ")
p2 (getcorner p1 "\nSpecify the opposite corner point: >> ")
)
(setq ss (ssget "W" (list (car p1)(cadr p1)) (list (car p2)(cadr p2)) (list (cons 0 "*TEXT")))
i -1
)
(repeat (sslength ss)
(setq en (ssname ss (setq i (1+ i)))
ip (cdr (assoc 10 (entget en)))
st (cdr (assoc 1 (entget en))))
;st (substr st (+ 2 (vl-string-position (ascii";") st ))(vl-string-position (ascii";") st ))
(if (eq "MTEXT" (cdr (assoc 0 (entget en))))(setq st (TTC_MText_Clear st)))
(setq tmp (mapcar '(lambda (x)(if (zerop (atof x)) x (atof x))) (string->list st " ")))
(while (cadr tmp)
(setq item (cons (car tmp)(cadr tmp)))
(setq dirty (cons item dirty))
(setq tmp (cddr tmp))))
(setq summary (_group_and_sum dirty))
(print summary)
(textscr); display result
;; --- do whatever you want with 'summary' here --- ;;
(princ)
)
(prompt "\n\t*** Type GPS to execute...")
(prin1)