@koseku3 wrote:
....
For instance i have texts in drawing as: 1 2 2 3 3 3
So i want a lisp which can give me a list like this:
1(1)
2(2)
3(3)
So i can know how many are there from each value at drawing?
....
Maybe not "better," but shorter, anyway:
(defun C:IQR ; = Integer Quantity Report
(/ ss qua inlist)
(setq
ss (ssget '((0 . "TEXT") (1 . "#,##,###")))
qua (sslength ss)
intlist ; list of text contents converted to integers
(mapcar 'atoi
(mapcar '(lambda (x) (cdr (assoc 1 (entget (cadr x)))))
(vl-remove-if '(lambda (y) (listp (cadr y))) (ssnamex ss))
); mapcar
); mapcar
); setq
(foreach int (vl-sort intlist '<); ascending numerical order, once each
(prompt (strcat "\n" (itoa int) " (" (itoa (- qua (length (vl-remove int intlist)))) ")"))
); foreach
(princ)
); defun
That also restricts it to only integer-content Text of up to three digits. If yours would be all only one digit as in your example, change the "#,##,###" in the filter list to just "#"; for two digits, "#,##"; if they might sometimes go to four digits, use "#,##,###,####"; etc.
It converts the text content to integers [which means it has to convert back for the prompts] because it can then more easily report them in order of numerical value. If you have a list of text-string contents like this:
("3" "1" "2" "123")
sorting by text-string value results in this:
("1" "123" "2" "3")
whereas converting them to integers and sorting gives this:
(1 2 3 123)
EDIT: As with @DannyNL's routine, it requires the User to select objects [though in each routine you can grab a whole area with a window, lasso, etc., and it will "see" only the appropriate objects]. But if you want it to report all such objects in the entire drawing, without the User needing to select them, change this line:
ss (ssget '((0 . "TEXT") (1 . "#,##,###")))
to this:
ss (ssget "_X" '((0 . "TEXT") (1 . "#,##,###")))
Kent Cooper, AIA