Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear Sir,
I want to required different type text counting.
Please see the example file.
Solved! Go to Solution.
Dear Sir,
I want to required different type text counting.
Please see the example file.
Solved! Go to Solution.
Try this, but first erase existing summary (green text) since it is created in wrong layer. In layer "bolts&nut" there must only be bolts (nuts) information.
(defun c:countBolts ( / *error* string_to_list ss i current bolt n pt summary)
;Hak_vz 16.february 2024
;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/differnt-type-text-counting/td-p/12565134
(defun *error* ( msg )
(if (not (member msg '("Function cancelled" "quit / exit abort")))
(princ)
)
(princ)
)
(defun string_to_list ( str del / pos )
(if (setq pos (vl-string-search del str))
(cons (substr str 1 pos) (string_to_list (substr str (+ pos 1 (strlen del))) del))
(list str)
)
)
(setq ss (ssget "X" '((0 . "TEXT") (8 . "BOLT&NUT") )) i -1 summary (list))
(cond
((and ss (> (sslength ss) 0))
(while (< (setq i (1+ i)) (sslength ss))
(setq
tocount (string_to_list (cdr(assoc 1(entget(ssname ss i)))) "-")
n (atoi (car tocount))
bolt (last tocount)
)
(cond
((assoc bolt summary)
(setq current (cdr (assoc bolt summary)) current (+ n current))
(setq summary (subst (cons bolt current)(assoc bolt summary) summary))
)
(T (setq summary (cons (cons bolt n) summary)))
)
)
(setq summary (vl-sort summary
'(lambda (a b)
(cond
((< (car a) (car b)))
((= (car a) (car b)) (< (cadr a) (cadr b)))
)
)
)
)
(setq pt (getpoint "\nPick summary insertion point >"))
(entmakex
(list
'(0 . "TEXT")
(cons 10 (trans pt 1 0))
(cons 40 (getvar 'textsize))
(cons 50 0)
(cons 8 "summary")
(cons 1 "%%UBOLT COUNTING SUMMARY")
(cons 62 3)
)
)
(foreach entry summary
(setq pt (mapcar '- pt (list 0 (* 1.5 (getvar 'textsize)))))
(if (wcmatch (car entry )"M*")
(entmakex
(list
'(0 . "TEXT")
(cons 10 (trans pt 1 0))
(cons 40 (getvar 'textsize))
(cons 50 0)
(cons 8 "summary")
(cons 1 (strcat (car entry) " = " (itoa (cdr entry))))
(cons 62 3)
)
)
(entmakex
(list
'(0 . "TEXT")
(cons 10 (trans pt 1 0))
(cons 40 (getvar 'textsize))
(cons 50 0)
(cons 8 "summary")
(cons 1 (strcat "M16x" (car entry) " = " (itoa (cdr entry))))
(cons 62 3)
)
)
)
)
)
)
(princ)
)
Miljenko Hatlak
Thanks for your reply,
Dear Sir,
Please modify the select text after and before option. not all text-counting.
@Gaganpatel Simply remove "X" filter in ssget.
(defun c:countBolts ( / *error* string_to_list ss i current bolt n pt summary)
;Hak_vz 16.february 2024
;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/differnt-type-text-counting/td-p/12565134
(defun *error* ( msg )
(if (not (member msg '("Function cancelled" "quit / exit abort")))
(princ)
)
(princ)
)
(defun string_to_list ( str del / pos )
(if (setq pos (vl-string-search del str))
(cons (substr str 1 pos) (string_to_list (substr str (+ pos 1 (strlen del))) del))
(list str)
)
)
(setq ss (ssget '((0 . "TEXT") (8 . "BOLT&NUT") )) i -1 summary (list))
(cond
((and ss (> (sslength ss) 0))
(while (< (setq i (1+ i)) (sslength ss))
(setq
tocount (string_to_list (cdr(assoc 1(entget(ssname ss i)))) "-")
n (atoi (car tocount))
bolt (last tocount)
)
(cond
((assoc bolt summary)
(setq current (cdr (assoc bolt summary)) current (+ n current))
(setq summary (subst (cons bolt current)(assoc bolt summary) summary))
)
(T (setq summary (cons (cons bolt n) summary)))
)
)
(setq summary (vl-sort summary
'(lambda (a b)
(cond
((< (car a) (car b)))
((= (car a) (car b)) (< (cadr a) (cadr b)))
)
)
)
)
(setq pt (getpoint "\nPick summary insertion point >"))
(entmakex
(list
'(0 . "TEXT")
(cons 10 (trans pt 1 0))
(cons 40 (getvar 'textsize))
(cons 50 0)
(cons 8 "summary")
(cons 1 "%%UBOLT COUNTING SUMMARY")
(cons 62 3)
)
)
(foreach entry summary
(setq pt (mapcar '- pt (list 0 (* 1.5 (getvar 'textsize)))))
(if (wcmatch (car entry )"M*")
(entmakex
(list
'(0 . "TEXT")
(cons 10 (trans pt 1 0))
(cons 40 (getvar 'textsize))
(cons 50 0)
(cons 8 "summary")
(cons 1 (strcat (car entry) " = " (itoa (cdr entry))))
(cons 62 3)
)
)
(entmakex
(list
'(0 . "TEXT")
(cons 10 (trans pt 1 0))
(cons 40 (getvar 'textsize))
(cons 50 0)
(cons 8 "summary")
(cons 1 (strcat "M16x" (car entry) " = " (itoa (cdr entry))))
(cons 62 3)
)
)
)
)
)
)
(princ)
)
Miljenko Hatlak
Dear Sir,
Thank you very much 🙏🙏🙏