SUM MTXT

SUM MTXT

sigmmadesigner
Advocate Advocate
441 Views
5 Replies
Message 1 of 6

SUM MTXT

sigmmadesigner
Advocate
Advocate

WHY CAN'T MY LSP FIND THE RESPECTIVE MTEXT, WHICH HAS THE INPUT, A BREAK AND IN THE SEQUENCE THE VALUE. IT CANNOT ORGANIZE THE LIST, ADD THE ITEMS BY THE INPUT AND ADD THE VALUE

 

(defun TOTAL (/ ss ent i txt valor texto QA QB QC QD)
(setq A 0.0 B 0.0 C 0.0 D 0.0 )
(setq ss (ssget "_X" '((0 . "MTEXT"))))
(if ss
(progn
(setq i 0)
(while (< i (sslength ss))
(setq ent (ssname ss i))
(setq txt (cdr (assoc 1 (entget ent))))
(if valor
(cond
((wcmatch txt "*A*") (setq QA (+ QA valor)))
((wcmatch txt "*B*") (setq QB (+ QB valor)))
((wcmatch txt "*C*") (setq QC (+ QC valor)))
((wcmatch txt "*D*") (setq QD (+ QD valor)))
)
)
)
(setq texto
(strcat
"\n TOTAL TEXT\n\n"
"SUM TEXT A → " (rtos QA 2 2) " \n"
"SUM TEXT B → " (rtos QB 2 2) " \n"
"SUM TEXT C → " (rtos QC 2 2) " \n"
"SUM TEXT D → " (rtos QD2 2) " \n"
)
)
(princ texto)
)
(princ "\nNo MTEXT found in drawing.")
)
(princ)
)

0 Likes
Accepted solutions (1)
442 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant
Accepted solution

There were too many issues with the code... You can compare the codes, see, and ask if you really want to know why.

 

(defun TOTAL (/ LM:str->lst ss ent i txt lst valor texto QA QB QC QD)
  
  ;; String to List  -  Lee Mac
  ;; Separates a string using a given delimiter
  ;; str - [str] String to process
  ;; del - [str] Delimiter by which to separate the string
  ;; Returns: [lst] List of strings
  
  (defun LM:str->lst ( str del / pos )
    (if (setq pos (vl-string-search del str))
      (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
      (list str)
      )
    )
  
  (setq QA 0.0 QB 0.0 QC 0.0 QD 0.0 )
  (setq ss (ssget "_X" '((0 . "MTEXT"))))
  (if ss
    (progn
      
      (repeat (setq i (sslength ss))
	(setq ent (ssname ss (setq i (1- i))))
	(setq txt (getpropertyvalue ent "Text"))
	(setq lst (LM:str->lst txt "\r\n"))
	(setq txt (car lst))
	(setq valor (atof (last lst)))
	(if (and txt valor)
	  (progn
	    (cond
	      ((wcmatch txt "*A*") (setq QA (+ QA valor)))
	      ((wcmatch txt "*B*") (setq QB (+ QB valor)))
	      ((wcmatch txt "*C*") (setq QC (+ QC valor)))
	      ((wcmatch txt "*D*") (setq QD (+ QD valor)))
	      
	      )
	    
	    (setq texto
		   (strcat
		     "\n TOTAL TEXT\n\n"
		     "SUM TEXT A › " (rtos QA 2 2) " \n"
		     "SUM TEXT B › " (rtos QB 2 2) " \n"
		     "SUM TEXT C › " (rtos QC 2 2) " \n"
		     "SUM TEXT D › " (rtos QD 2 2) " \n"
		     )
		  )
	    (princ texto)
	    ))))
    (princ "\nNo MTEXT found in drawing.")
    )
  (princ)
  )

 

Message 3 of 6

sigmmadesigner
Advocate
Advocate

CONGRATULATIONS, CHECKMATE!!!😀
I AM NOT A PROGRAMMER, BUT I BELIEVE THAT THE ADD FRAGMENT SEARCHES FOR THE NUMBER THAT IS FOUND AFTER \\P BECAUSE WHAT IS BEFORE IT IS TEXT, AND THEREFORE, FOR THE ADDING PROCESS ALL TEXT IS DISCARDED.
I GOT CLOSER!!

0 Likes
Message 4 of 6

Sea-Haven
Mentor
Mentor

Just a suggestion use lowercase in posts. Capitals can be known as shouting, used here some times when people get frustrated with a poster not following instructions.

0 Likes
Message 5 of 6

sigmmadesigner
Advocate
Advocate

Hello, I didn't know there was an etiquette rule, the capital letters were to separate programming and conversation... but, noted!

The next, i will follow this rule. Sorry if I was rude at any time.😅

Gratefulness!!!

0 Likes
Message 6 of 6

Sea-Haven
Mentor
Mentor

Not a problem at all. Use the </> for your code up at the top, it will separate it.