I've discovered a truly-remarkably-convenient factoid for this situation:
(getpropertyvalue MtextEntityName "text")
returns the plain text string content of Mtext minus any and all internal formatting! No need to go through StripMtext or other sophisticated routine!
If it is valid to assume that the numerical part you want from your Text/Mtext always has a + sign just before it and there is no other + sign before that, and is always the last part with the exception of a possible concluding ), and is always an integer value, then this [in simplest terms] works for me, with plain Text and/or Mtext, with or without concluding ), and if the Mtext has internal formatting including inside the numerical part:
(defun C:INTDELTA (/ tstr +num T1 T2)
(defun tstr (te); text string from text/mtext entity [unformatted if Mtext]
(getpropertyvalue te (if (= (cdr (assoc 0 (entget te))) "TEXT") "textstring" "text"))
)
(defun +num (str); number part following +
(atoi (vl-string-right-trim ")" (substr str (+ 2 (vl-string-position 43 str)))))
)
(setq
T1 (car (entsel "\nSelect Text/Mtext item 1: "))
T2 (car (entsel "\nSelect Text/Mtext item 2: "))
delta (- (+num (tstr T1)) (+num (tstr T2)))
); setq
)
It can be expanded to account for a possible - instead of the +, or [a little more complicated] neither. It could take the absolute value if the result is negative, if you want the raw difference and it doesn't matter in which order you pick. It could be made to allow for non-integer values.
It leaves the difference in the 'delta' variable to do something else with if you want. It just returns the difference as a number at the command line, but could put that into a prompt or an alert instead.
It could get the usual enhancements, such as verifying that you selected the right kinds of objects, etc. But see whether, under my assumptions and in this basic form, it reports the difference correctly under your actual conditions.
Kent Cooper, AIA