Counting and sum of the TEXT

Counting and sum of the TEXT

Gaganpatel
Collaborator Collaborator
4,431 Views
19 Replies
Message 1 of 20

Counting and sum of the TEXT

Gaganpatel
Collaborator
Collaborator

Dear Sir,

 

I want to count and make the sum of it by the help of lisp file.

1*M16*40

2*M16*35

8*M16*50

1*M16*40

2*M16*35

2*M16*45

1*M16*6PW

1*M16*10PW

2*M16*45

2*M16*35

1*M16*10PW

1*M16*6PW

only select object text sum not total drawing text sum.

Final result will be

M16x35-6

M16x40-2

M16x45-4

PW16x6-2

PW16x10-2

 

 

0 Likes
Accepted solutions (2)
4,432 Views
19 Replies
Replies (19)
Message 2 of 20

Gaganpatel
Collaborator
Collaborator

Dear Sir,

 

I want to count and make the sum of it by the help of lisp file.

1*M16*40

2*M16*35

8*M16*50

1*M16*40

2*M16*35

2*M16*45

1*M16*6PW

1*M16*10PW

2*M16*45

2*M16*35

1*M16*10PW

1*M16*6PW

only select object text sum not total drawing text sum.

Final result will be

M16x35-6

M16x40-2

M16x45-4

PW16x6-2

PW16x10-2

 

 

 
0 Likes
Message 3 of 20

Gaganpatel
Collaborator
Collaborator

PLEASE REPLAY

0 Likes
Message 4 of 20

ВeekeeCZ
Consultant
Consultant

What are you talking about? Tell us some background. Maybe post some screenshot or dwg.

What is M16, is it some variable? What are 6MW or 10PW? Remember we know nothing about your area, your industry, your national customs...

0 Likes
Message 5 of 20

Gaganpatel
Collaborator
Collaborator

 

Dear Sir,

Please replay

 

Please find the attached example file.

0 Likes
Message 6 of 20

ВeekeeCZ
Consultant
Consultant

Sorry, can't help you, don't understand you.

 

@Anonymous LOOK HERE for more context. 

0 Likes
Message 7 of 20

Gaganpatel
Collaborator
Collaborator

dear sir,

text writing will be changed

old text

M16x45-12

M16x50-8

M16x55-4

new text

1*M16*40

2*M16*35

8*M16*50

1*M16*40

2*M16*35

2*M16*45

1*M16*6PW

i am trying old lisp file but not working

please help

 

0 Likes
Message 8 of 20

pbejse
Mentor
Mentor

@Gaganpatel wrote:

 

i am trying old lisp file but not working

please help

 


Perhaps this one  MULTI TYPES OF TEXT SUM by DannyNL

 

0 Likes
Message 9 of 20

pbejse
Mentor
Mentor

@ВeekeeCZ wrote:

 

@Anonymous LOOK HERE for more context. 


 

Would love to help, but apparently, I did not even come up with a solution for that 😄

 

not me.PNG

 

 

 

0 Likes
Message 10 of 20

Gaganpatel
Collaborator
Collaborator

Dear sir,

text writing will be changed.

old text

1-C

2-D

5-A

new text

2*M16*35

2*M16*45

1*M16*6PW

1*M16*10PW

2*M16*45

2*M16*35

1*M16*10PW

i am trying this lisp but not working

please help .

 

0 Likes
Message 11 of 20

Gaganpatel
Collaborator
Collaborator

Please any body answer

please help

0 Likes
Message 12 of 20

CADaSchtroumpf
Advisor
Advisor

With your example, seem to work...

Try it if can help you

 

((lambda ( / js M16*40 M16*45 M16*50 M16*55 n en dxf_txt)
  (setq js (ssget "_X" '((0 . "TEXT") (67 . 0) (8 . "Bolt_Qty") (62 . 40) (7 . "BoltNut"))))
  (cond
    (js
      (setq M16*40 0 M16*45 0 M16*50 0 M16*55 0)
      (repeat (setq n (sslength js))
        (setq
          ent (ssname js (setq n (1- n)))
          dxf_txt (cdr (assoc 1 (entget ent)))
        )
        (foreach el '("?`*M16*40" "?`*M16*45" "?`*M16*50" "?`*M16*55")
          (if (wcmatch dxf_txt el)
            (set (read (substr el 4)) (1+ (eval (read (substr el 4)))))
          )
        )
      )
    )
  )
  (mapcar '(lambda (x) (print (strcat x "-" (itoa (eval (read x)))))) '("M16*40" "M16*45" "M16*50" "M16*55"))
  (prin1)
))

 

0 Likes
Message 13 of 20

Gaganpatel
Collaborator
Collaborator

 

Dear Sir,

 

Not only M16 bolt

M20*55*5

M20*85*2

M20*65*5

 

 

0 Likes
Message 14 of 20

Gaganpatel
Collaborator
Collaborator

 

 

Please help me sir

0 Likes
Message 15 of 20

dbhunia
Advisor
Advisor

Try this......(Considering all Bolts are in Layer "Bolt_Qty")

 

(defun C:BCNT (/ Toatl);;Add Temp variables here
(setq Bolt_lst (list "M16*6" "M16*35" "M16*40" "M16*45" "M20*55" "M20*65" "M20*85" "16*6PW"));;Add Bolts Here in this format
(setq selectionset (ssget "_A" '((0 . "TEXT") (8 . "Bolt_Qty"))))
(foreach b Bolt_lst
   (setq count 0)
   (repeat (setq N (sslength selectionset))
	(setq Data (ssname selectionset (setq N (- N 1))))
	(setq EntityData (entget Data))
	(setq text (cdr (assoc 1 EntityData)))
	(if (/= (vl-string-search b text) nil)
	    (progn
		(setq text_lst (LM:str->lst text "*"))
		(setq no (atoi (nth 0 text_lst)))
		(setq count (+ count no))
	    )
	)
   )
   (if (= (vl-string-search "PW" b) nil)
   	(print (setq result (strcat (vl-string-subst "X" "*" b) "-" (rtos count))))
	(progn
   		(setq result (strcat (vl-string-subst "X" "*" b) "-" (rtos count)))
		(print (setq result (strcat "PW" (vl-string-subst "" "PW" result))))
	)
   )
   (setq Toatl (cons result Toatl))
)
(print Toatl)
(princ)
)
(defun LM:str->lst ( str del / len lst pos )
    (setq len (1+ (strlen del)))
    (while (setq pos (vl-string-search del str))
	   (setq lst (cons (substr str 1 pos) lst))
           (setq str (substr str (+ pos len)))
    )
    (reverse (cons str lst))
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 16 of 20

Gaganpatel
Collaborator
Collaborator

 

Dear Sir,

This lisp not working in command BCNT

0 Likes
Message 17 of 20

dbhunia
Advisor
Advisor

This is working with your attached drawing to me.......(AutoCAD 2018)......

 

Try this.....

 

(defun C:BCNT (/ Toatl);;Add Temp variables here
(vl-load-com)
(setvar 'cmdecho 0)
(setq Bolt_lst (list "M16*6" "M16*35" "M16*40" "M16*45" "M20*55" "M20*65" "M20*85" "16*6PW"));;Add Bolts Here in this format
(setq selectionset (ssget "_A" '((0 . "TEXT") (8 . "Bolt_Qty"))))
(foreach b Bolt_lst
   (setq count 0)
   (repeat (setq N (sslength selectionset))
	(setq Data (ssname selectionset (setq N (- N 1))))
	(setq EntityData (entget Data))
	(setq text (cdr (assoc 1 EntityData)))
	(if (/= (vl-string-search b text) nil)
	    (progn
		(setq text_lst (LM:str->lst text "*"))
		(setq no (atoi (nth 0 text_lst)))
		(setq count (+ count no))
	    )
	)
   )
   (if (= (vl-string-search "PW" b) nil)
   	(setq result (strcat (vl-string-subst "X" "*" b) "-" (rtos count)))
	(progn
   	   (setq result (strcat (vl-string-subst "X" "*" b) "-" (rtos count)))
	   (setq result (strcat "PW" (vl-string-subst "" "PW" result)))
	)
   )
   (setq Toatl (cons result Toatl))
)
(setq txtpt (getpoint "\nSelect location to print Calculation:"))
(command "text" txtpt "" "%%uBolt Summation:")
(foreach Item (reverse Toatl)
       (command "_TEXT" "" Item)
)
(setvar 'cmdecho 1)
(princ)
)
(defun LM:str->lst ( str del / len lst pos )
    (setq len (1+ (strlen del)))
    (while (setq pos (vl-string-search del str))
	   (setq lst (cons (substr str 1 pos) lst))
           (setq str (substr str (+ pos len)))
    )
    (reverse (cons str lst))
)

 

What message you are getting???????


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 18 of 20

Gaganpatel
Collaborator
Collaborator
Accepted solution

This lisp is working ok but i want to option

selecting drawing bolt counting option not total drawing bolt count.

please help.

 

0 Likes
Message 19 of 20

dbhunia
Advisor
Advisor
Accepted solution

@Gaganpatel wrote:

This lisp is working ok but i want to option

selecting drawing bolt counting option not total drawing bolt count.

please help.

 


change....this

(setq selectionset (ssget "_A" '((0 . "TEXT") (8 . "Bolt_Qty"))))

To.....

(setq selectionset (ssget '((0 . "TEXT") (8 . "Bolt_Qty"))))

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 20 of 20

Gaganpatel
Collaborator
Collaborator

Thank you very much sir

0 Likes