DIFFERNT TYPE TEXT COUNTING

DIFFERNT TYPE TEXT COUNTING

Gaganpatel
Collaborator Collaborator
563 Views
6 Replies
Message 1 of 7

DIFFERNT TYPE TEXT COUNTING

Gaganpatel
Collaborator
Collaborator

Dear Sir,

 

I want to required different type text counting.

Please see the example file.

 

 

0 Likes
Accepted solutions (1)
564 Views
6 Replies
Replies (6)
Message 2 of 7

pendean
Community Legend
Community Legend

Not enough information @Gaganpatel 

Can you elaborate more on your need please? This is all you posted

pendean_0-1708113050262.png

 

0 Likes
Message 3 of 7

hak_vz
Advisor
Advisor

@Gaganpatel 

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)
)

 

 

Screenshot 2024-02-16 210925.png

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 4 of 7

chrmtwlrl
Community Visitor
Community Visitor

thankss

0 Likes
Message 5 of 7

Gaganpatel
Collaborator
Collaborator

Thanks for your reply,

 

Dear Sir,

 

Please modify the select text after and before option. not all text-counting.

 

0 Likes
Message 6 of 7

hak_vz
Advisor
Advisor
Accepted solution

@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

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 7 of 7

Gaganpatel
Collaborator
Collaborator

Dear Sir,

Thank you very much 🙏🙏🙏

0 Likes