Jump to content

Text Math


Lee Mac

Recommended Posts

Following this thread and this thread, I thought I'd write a complementary function to allow the user to operate on numbers inside text.

 

Example:

 

TextMath.gif

 

;;;¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,;;;
;;;ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,¤º°`°º¤;;;
;;                                                                               ;;
;;                                                                               ;;
;;                          --=={  Text Math  }==--                              ;;
;;                                                                               ;;
;;  The program will allow the user to perform mathematical operations on Text,  ;;
;;  MText, Dimensions & Attributes containing numerical data.                    ;;
;;                                                                               ;;
;;  The user is prompted to select an operation (Addition, Subtraction,          ;;
;;  Division & Multiplication); and an operand. The user is then prompted to     ;;
;;  make a selection of objects to modify.                                       ;;
;;                                                                               ;;
;;  If a non-commutative operation is chosen, the user will be prompted to       ;;
;;  specify the order of operation.                                              ;;
;;                                                                               ;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                                               ;;
;;  FUNCTION SYNTAX:  TextMath  /  TMA                                           ;;
;;                                                                               ;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                                               ;;
;;  AUTHOR:                                                                      ;;
;;                                                                               ;;
;;  Copyright © Lee McDonnell, April 2010. All Rights Reserved.                  ;;
;;                                                                               ;;
;;      { Contact: Lee Mac @ TheSwamp.org, CADTutor.net }                        ;;
;;                                                                               ;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                                               ;;
;;  VERSION:                                                                     ;;
;;                                                                               ;;
;;  ø 1.0   ~¤~     9th April 2010   ~¤~   º First Release                       ;;
;;...............................................................................;;
;;  ø 1.1   ~¤~    11th April 2010   ~¤~   º Updated to include Dimensions.      ;;
;;                                         º Updated ParseNumbers function.      ;;
;;...............................................................................;;
;;                                                                               ;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                                               ;;
;;;¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,;;;
;;;ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,¤º°`°º¤;;;

Be careful when using with MText that contains nested formatting, comments are welcome.

 

Lee

 

--=={ Code Updated to Version 1.1 }==--

TextMath V1.1.lsp

  • Like 1
Link to comment
Share on other sites

  • 4 months later...

Found this routine helpful last week, had to reudce a series of levels by a constant amount. The text contained both level info & characters, worked like a charm. It was simple to use & did exactly what it said on the tin

 

Nice work on it Lee

Link to comment
Share on other sites

  • 3 years later...

This program is VERY useful, but I need the ability to specify the number of decimal points the resulting solution generates (i.e. 710.75 - 0.25 = 710.50 not 710.5). It would also be useful to only modify text that fits a particular mask (i.e. ###.##) where there are multiple numbers within an object of text (i.e. 12" E. INV. = 734.44, I don't want to perform math on the 12" text).

 

Any chance of a update with these features?

Link to comment
Share on other sites

  • 8 months later...

5rd, 4nd and 3st --- I like it!

But closing in on this dilemma, is there a clean way of getting that to work?

1st but 11th, 2nd but 12th, 3rd but 13th

Hard to just take the number from the ones column. And what happens when you subtract 2 from 2nd? 0nd :lol:

About 14 years ago, I wrote a couple of little functions for adding or subtracting 1, 10, 100 or your own amount to change numeral text and attributes.

Link to comment
Share on other sites

5rd, 4nd and 3st --- I like it!

But closing in on this dilemma, is there a clean way of getting that to work?

1st but 11th, 2nd but 12th, 3rd but 13th

Hard to just take the number from the ones column. And what happens when you subtract 2 from 2nd? 0nd :lol:

About 14 years ago, I wrote a couple of little functions for adding or subtracting 1, 10, 100 or your own amount to change numeral text and attributes.

 

Maybe that was a bad example for the demonstration, as this old program is really only intended to modify the numerical content in the text and does not attempt to interpret the surrounding non-numerical content.

 

But where ordinals are concerned, perhaps the following function could be of use:

(defun ordinal ( n )
   (cond ((nth (rem n 10) '(nil "st" "nd" "rd"))) ("th"))
)

_$ (ordinal 1)
"st"
_$ (ordinal 2)
"nd"
_$ (ordinal 3)
"rd"
_$ (ordinal 4)
"th"

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...