Jump to content
Lee Mac

Text Math

Recommended Posts

Lee Mac

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

Share this post


Link to post
Share on other sites
VovKa
(ParseNumbers "-1.5")

Share this post


Link to post
Share on other sites
Lee Mac

Arghh! Will certainly get that fixed! :)

 

Thanks mate

Share this post


Link to post
Share on other sites
alanjt
(ParseNumbers "-1.5")

 

(ParseNumbers ".3")

I meant to mention it when you first posted.

Share this post


Link to post
Share on other sites
Lee Mac
(ParseNumbers ".3")

I meant to mention it when you first posted.

 

That behaves as it should? :huh:

 

Returns:

 

("." 3)

Share this post


Link to post
Share on other sites
Lee Mac

VovKa, please try Version 1.1 :)

Share this post


Link to post
Share on other sites
alanjt
That behaves as it should? :huh:

 

Returns:

 

("." 3)

I would think you would want 0.3

Share this post


Link to post
Share on other sites
Lee Mac
I would think you would want 0.3

 

But ".3" is not a valid number.

Share this post


Link to post
Share on other sites
alanjt
But ".3" is not a valid number.

Some people may type it that way.

 

Command: (atof ".3")
0.3

Share this post


Link to post
Share on other sites
alanjt

Do what you will with the information. I just wanted you to be aware.

Share this post


Link to post
Share on other sites
Lee Mac
Do what you will with the information. I just wanted you to be aware.

 

OK, thanks.

Share this post


Link to post
Share on other sites
VovKa
VovKa, please try Version 1.1 :)

there is no need to try, i trust you :)

Share this post


Link to post
Share on other sites
Lee Mac
there is no need to try, i trust you :)

 

Haha... :P

Share this post


Link to post
Share on other sites
jammie

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

Share this post


Link to post
Share on other sites
Lee Mac

Thanks Jammie, I feel honoured that you could make use of it :)

Share this post


Link to post
Share on other sites
cport

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?

Share this post


Link to post
Share on other sites
yathishkumar

good job i like it

 

thank you very much

Share this post


Link to post
Share on other sites
Lee Mac

Thank you :)

Share this post


Link to post
Share on other sites
LibertyOne

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.

Share this post


Link to post
Share on other sites
Lee Mac
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"

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...