lisp multiply mtext content

lisp multiply mtext content

nachoamarante.junk
Explorer Explorer
1,021 Views
8 Replies
Message 1 of 9

lisp multiply mtext content

nachoamarante.junk
Explorer
Explorer

HI, I NEED A LISP THAT MAKES THE MULTIPLY OPERATION INCLUDED IN MULTIPLE MTEXT

FOR EXAMPLE, AN MTEXT CONTAINING "10*80", ANOTHER "5*3" (RESULT=2415)

 

I NEED TO SELECT THEM ALL AND GIVE ME THE RESULT OF THE SUM OF ALL THE MULTIPLICATIONS

 

THANKS!

0 Likes
Accepted solutions (2)
1,022 Views
8 Replies
Replies (8)
Message 2 of 9

ВeekeeCZ
Consultant
Consultant

Post a dwg with a few real examples.

0 Likes
Message 3 of 9

nachoamarante.junk
Explorer
Explorer

here it is

0 Likes
Message 4 of 9

ВeekeeCZ
Consultant
Consultant

Really, the multiplication is ALL the mtexts contain...

0 Likes
Message 5 of 9

ronjonp
Mentor
Mentor
Accepted solution

Here's a quick one for each line...

 

(defun c:foo (/ n o s str)
  (if (setq s (ssget '((0 . "MTEXT") (1 . "*`**"))))
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (setq str (vla-get-textstring (setq o (vlax-ename->vla-object e))))
      (setq n (eval (cons '* (read (strcat "(" (vl-string-translate "*" " " str) ")")))))
      (vla-put-textstring o (strcat str " = " (vl-princ-to-string n)))
    )
  )
  (princ)
)

And one to tally them up:

(defun c:foo (/ i n o s str)
  (setq i 0)
  (if (setq s (ssget '((0 . "MTEXT") (1 . "*`**"))))
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (setq str (vla-get-textstring (setq o (vlax-ename->vla-object e))))
      (setq n (eval (cons '* (read (strcat "(" (vl-string-translate "*" " " str) ")")))))
      (setq i (+ i n))
      ;; (vla-put-textstring o (strcat str " = " (vl-princ-to-string n)))
    )
  )
  (if (and (> i 0)
	   (setq o (car (entsel "\nPick text to place result: ")))
	   (= "MTEXT" (cdr (assoc 0 (entget o))))
      )
    (vla-put-textstring (vlax-ename->vla-object o) (vl-princ-to-string i))
  )
  (princ)
)

 

0 Likes
Message 6 of 9

ВeekeeCZ
Consultant
Consultant
Accepted solution

Since mine is a little different... 

 

(defun c:Multiplication ( / n s i c)

  (if (setq n 0 s (ssget '((0 . "MTEXT") (1 . "*#`*#*"))))
    (repeat (setq i (sslength s))
      (setq c (cdr (assoc 1 (entget (ssname s (setq i (1- i))))))
	    n (+ n (* (atoi c) (atoi (substr c (+ 2 (vl-string-search "*" c)))))))))
  (princ "\nResult: ") (princ (itoa n))
  (princ)
  )

 

Message 7 of 9

nachoamarante.junk
Explorer
Explorer

Thank you both, you have saved me a lot of time. Happy Holidays!

0 Likes
Message 8 of 9

ronjonp
Mentor
Mentor

@nachoamarante.junk wrote:

Thank you both, you have saved me a lot of time. Happy Holidays!


Glad to help! 🙂

0 Likes
Message 9 of 9

vladimir_michl
Advisor
Advisor

You can even have a general expression evaluator from VBscript - see the EvalText LISP file on cadforum.cz

 

evaltext.gif

 

Vladimir Michl, www.arkance-systems.cz - www.cadforum.cz