Text Counting and SUM

Text Counting and SUM

Gaganpatel
Collaborator Collaborator
848 Views
12 Replies
Message 1 of 13

Text Counting and SUM

Gaganpatel
Collaborator
Collaborator

Dear Sir,

I have required text counting and sum.

2-M16x35

3-M16x45

2-M16x50

3-M16x55

2-M16x35

2-M16x40

2-PW16x6

Final Result

M16x35-4

M16x40-2

M16x45-3

M16x50-2

M16x55-3

PW16x6-2

0 Likes
849 Views
12 Replies
Replies (12)
Message 2 of 13

Automohan
Advocate
Advocate

It looks not text counting text editing

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Message 3 of 13

Gaganpatel
Collaborator
Collaborator
Any Body please help lisp programming
0 Likes
Message 4 of 13

Sea-Haven
Mentor
Mentor

This is part 2 of your other post re quantities. I commented about counting bolts and the difficulty with the dwg not being simple to extract data.

0 Likes
Message 5 of 13

Gaganpatel
Collaborator
Collaborator
Dear Sir,
I agree difficult but please solve my post.
0 Likes
Message 6 of 13

ronjonp
Advisor
Advisor

@Gaganpatel wrote:
Dear Sir,
I agree difficult but please solve my post.

Give this a try. Not that difficult 🙂

 

(defun c:foo (/ _foo a i p r s)
  ;; RJP » 2023-05-01
  (defun _foo (str) (substr str 1 (vl-string-search "-" str)))
  (cond
    ((setq s (ssget "_X" '((0 . "TEXT") (1 . "*-*"))))
     (setq s (mapcar 'cadr (ssnamex s)))
     (setq s (vl-sort (mapcar 'vla-get-textstring (mapcar 'vlax-ename->vla-object s)) '>))
     (while (setq a (car s))
       (setq p (substr a (setq i (+ 2 (vl-string-search "-" a)))))
       (setq a (vl-remove-if-not '(lambda (x) (wcmatch x (strcat "*" p))) s))
       (setq r (cons (apply '+ (mapcar 'atoi (mapcar '_foo a))) r))
       ;; Print results to command line
       (princ (strcat "\n" p " - " (vl-princ-to-string (apply '+ (mapcar 'atoi (mapcar '_foo a))))))
       (foreach x a (setq s (vl-remove x s)))
     )
     (princ (strcat "\n" (vl-princ-to-string (apply '+ r))))
     (textscr)
    )
  )
  (princ)
)

 

Result to command line:

 

Command: FOO
M16x55-16
M16x40-27
M16x45-8
PW16x8-1
PW16x6-1
PW16x5-1
PW16x4-1
PW16x10-1

 

You do have one callout that will not be tallied because it does not separate the number with a "-".

ronjonp_0-1682959257450.png

 

0 Likes
Message 7 of 13

Gaganpatel
Collaborator
Collaborator
Dear Sir,

Sum Result in shown
I want to sum result text place in select location and sum result output in select object (After & Before)
0 Likes
Message 8 of 13

ronjonp
Advisor
Advisor

@Gaganpatel wrote:
Dear Sir,

Sum Result in shown
I want to sum result text place in select location and sum result output in select object (After & Before)

@Gaganpatel 

Copy and paste from the command line into your drawing. It's still faster than your current process. 😎

2023-05-01_11-09-54.gif

I added the sum to the code above so try it again.

M16x55-16
M16x40-27
M16x45-8
PW16x8-1
PW16x6-1
PW16x5-1
PW16x4-1
PW16x10-1
56

0 Likes
Message 9 of 13

Kent1Cooper
Consultant
Consultant

@Gaganpatel wrote:
.... sum result output in select object (After & Before)

There's nothing that seems like After & Before in the sample drawing.  What do you mean by that?  After & Before what?

Kent Cooper, AIA
0 Likes
Message 10 of 13

Gaganpatel
Collaborator
Collaborator

Dear Sir,

 

Please see the After and Before example image

TextCount_ Example.gif

0 Likes
Message 11 of 13

ronjonp
Advisor
Advisor

@Gaganpatel You already have code to do what you're asking?

 

My code above will do the same as long as the quantity is separated by "-" then a description. The only difference is it prints the results to the command line.

0 Likes
Message 12 of 13

komondormrex
Mentor
Mentor

hey,

check code below

 

;**********************************************************************************************************************

(defun parse_text (text_ename)
	(setq text_string (cdr (assoc 1 (entget text_ename)))
  	      quantity (atoi (substr text_string 1 (setq minus_position (vl-string-position (ascii "-") text_string))))
	      item (substr text_string (+ 2 minus_position))
	)
	(cons item quantity)
)

;**********************************************************************************************************************

(defun c:calculate_items (/ text_sset assoc_result_list item_assoc_list_found item_assoc_list)
	(foreach text (setq text_sset (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "text") (1 . "*-*")))))))
		(if (setq item_assoc_list_found (assoc (car (setq item_assoc_list (parse_text text))) assoc_result_list))
			(setq assoc_result_list (subst (cons (car item_assoc_list)
							     (+ (cdr item_assoc_list_found)
								(cdr item_assoc_list)
							     )
						       )
						       item_assoc_list_found
						       assoc_result_list
			      			)
			)
		  	(setq assoc_result_list (append assoc_result_list (list item_assoc_list)))
		)
	)
  	(setq assoc_result_list (vl-sort assoc_result_list '(lambda (item_1 item_2) (< (car item_1) (car item_2)))))
	(vla-put-height
	  	(vla-addmtext (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
	                      (vlax-3d-point (trans (getpoint "\nPick point for mtext placing") 1 0))
	                      0
		  	      (apply 'strcat (mapcar '(lambda (item) (strcat (car item)
									     "\t - "
									     (itoa (cdr item))
									     "\\P"
								     )
						      )
						      assoc_result_list
				     	     )
			      ) 
	        )
		(cdr (assoc 40 (entget (car text_sset))))
	)
  	(princ)
)

;**********************************************************************************************************************
0 Likes
Message 13 of 13

Sea-Haven
Mentor
Mentor

Hi guys need to look at other posts as well, wants a quantities schedule of all the beams and plates as well. 

 

That is why I said its like part 2 of a request. I mentioned counting bolts in other post.

 

Structure Drawing to Excel BOM Automatic - Autodesk Community - AutoCAD

0 Likes