I want to count bolts

I want to count bolts

avinash00002002
Collaborator Collaborator
419 Views
7 Replies
Message 1 of 8

I want to count bolts

avinash00002002
Collaborator
Collaborator

Hi!

I have some text for bolt and it needs to count.

 

3-M16x40

Qty-Bolt Size X length 

qTY VARY 1 TO n NUMBER

bolt size it shall be M12, M16, M20, M24 

BOLT LENGTH = 30 TO 200MM.

IT WILL BE MIXTED BOLT SIZES and it includes with *, "*" means antitheft bolt e.g. 3-M16x40*

 

it has also mixed text with pack washer 3-M16x40

qty. - PW16 X thickness of washer.

 

ATTACHED DRAWING ALSO.

 

 

0 Likes
420 Views
7 Replies
Replies (7)
Message 2 of 8

hak_vz
Advisor
Advisor

 

(defun c:cbolts ( / LM:Unique string_to_list count_items ss i j bolts bolts_counts bolt_names item);
	(defun LM:Unique ( l )(if l (cons (car l) (LM:Unique (vl-remove (car l) (cdr l))))))
	(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)
		)
	)
	(defun count_items (x lst / count)(setq count 0)(foreach y lst (if (equal x y) (setq count (1+ count)))) count)
			
	(setq ss (ssget '((0 . "TEXT")(8 . "5_Bolts"))) i -1 bolts_counts (list))
	(cond
		((and ss (>= (sslength ss) 1))

			(while (<(setq i (1+ i)) (sslength ss))
				(setq item (string_to_list  (cdr (assoc 1 (entget (ssname ss i)))) "-"))
				(setq j -1)
				(while (< (setq j (1+ j)) (atoi (car item)))(setq bolts (cons (cadr item) bolts)))
			)
			(setq bolt_names (vl-sort (LM:Unique bolts) '<))
			(foreach bolt bolt_names(setq bolts_counts (append bolts_counts (list (count_items bolt bolts)))))
			(setq i -1)
			(while (< (setq i (1+ i)) (length bolt_names))(princ (strcat "\n" (nth i bolt_names) "," (itoa(nth i bolts_counts)))))
		)
		(T (princ "\nNothing selected!"))
	)
	(princ)
)
(princ "\nType CBOLTS to count bolts types textmarks!")
(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.
Message 3 of 8

Sea-Haven
Mentor
Mentor

Very nice @hak_vz, pretty simple to change the while on line 23 to make a list then can add a table with results.


("PW16x6 3" "M20x60* 3" "M20x50* 15" "M20x45* 6" "M20x40* 12" "M16x50* 32" "M16x45* 37" "M16x40* 88")

 

0 Likes
Message 4 of 8

Pihu_2024
Enthusiast
Enthusiast

Dear Sir,

Please modify this Programming, Required Bolt Count Table List Place in text.

 

0 Likes
Message 5 of 8

hak_vz
Advisor
Advisor

@avinash00002002  @Pihu_2024 

There are many scripts about transferring result to table.

I would really like to see you trying to write some code.

If you don't learn how to write autolisp code, all our effort is meaningless.

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.
Message 6 of 8

hak_vz
Advisor
Advisor

@Sea-Haven Yes it is butt I would like OP to come up with some code.

Idea is to make this forum better and to guide new members to learn how to write some code.

How many times have you answered similar requests like this one?

There are so many redundant posts, that all older and very valuable code stored in posts older than 10 years will be moved to backups

and I don't know will it be easily accessible.  

 

This forum is because of this redundancy miles away to forums like theswamp.org. 

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 8

Sea-Haven
Mentor
Mentor

Agree @avinash google make a table from a list, there are plenty of examples here.

0 Likes
Message 8 of 8

ec-cad
Collaborator
Collaborator

This model of the Lisp above, adds a simple 'Text' report of the items selected.

 

ECCAD

 

0 Likes