View Full Version : Adding numbers, ingoring letters
Robert.Hall
2005-10-13, 02:38 PM
I have seen several lisp routines that add up numerical text values.
An issue I have is what to do when the numerical value is in the middle of a setence.
For example: Incoming blank weight=12.25 Kg.
Does anyone have a lisp routine that will add up the numeric characters and
ignore the rest of the string???? I have these lines inserted as dtext.
timothyjturner
2005-10-13, 04:43 PM
I'm not sure about this but I have an idea...there are several string-handling functions that are useful. This may be way too complicated and there could be an easier solution. The only way I could think to do it would be to do the following:
1. vl-string-position - Use this command to search for the position of characters 0-9 individually. Once you find the position of all these characters. Store the position futhest to the right in a variable and the position furthest to the left in a variable. Disreguard the rest.
2. Use vl-string-left-trim and vl-string-right-trim to remove the number from the string.
3. Do desired calculations
4. Use vl-string-subst to substitute new value for old value into old string.
For the details on how to use these functions, access the help files that come with AutoCAD.
Note: This would only work if the string only contained one number.
CAB2k
2005-10-13, 05:43 PM
Here is a little ditty I wrote & may be of use to you.
Robert.Hall
2005-10-13, 07:26 PM
That is a great routine, however, I am trying to do some simple addition here so that I do not have to use by Abacus all the time. I want to create a total material usage from adding up the weights of the component parts. Where I am stuck is with having the numbers surrounded by letters.
CAB2k
2005-10-13, 08:45 PM
Sorry I should have read your post more closely.
The subroutine used to increment the number may be modified to return the number.
Also there is a routine over at the swamp that will do just what you are looking for.
Search "number from string"
mathew.worland
2005-10-14, 02:54 PM
If you know what letters you need to ignore you can use this
(defun FtgToReal (FTG /)
(vl-string-subst "" "'" FTG)
)
I use this to remove the foot mark.
peter
2005-10-14, 05:11 PM
try this routine
T.Willey
2005-10-18, 01:21 AM
See if this one works for you.
T.Willey
2005-10-18, 01:41 AM
Here is the revised version to work when there is a coma in the number.
Robert.Hall
2005-10-18, 02:33 PM
Thats is a great routine........what am I suppose to do when it prompts to create a new text object. For some reason I cannot figure that out and I bet it is easy. :screwy:
I also found using the undo command with this lisp routine will crash AutoCad.
Robert.Hall
2005-10-18, 02:34 PM
I had to enter another post because I was at 666, very spooky for october.
Avoidance is everything.
T.Willey
2005-10-18, 05:05 PM
On my comp, once you get the total, you either can hit enter to replace, or type c to create a new text object. If you hit c, then it should just prompt you to pick a point, and that is the new insertion point for the new text. Is that not happening on you comp? And I can undo without a problem. I will check it out a little more. I just did a quick little test. I'm useing A2k4.
Tim
jondevries
2005-12-29, 07:42 PM
I agree, great routine.
However.... it returns a value of 'feet and inches', which I have to multiply by 12 and add the inches to get the numerical value. Using this to add values in a chart, and need integers, not dimensional values.
Any ideas?
Thanks
T.Willey
2005-12-29, 09:19 PM
It returns the value according to the units the drawing is setup to be. If you are in architectural units, then it puts it in feet and inches, if you are in decimal, then it will return a decimal. You can hard code it to be decimal. Find and replace all text like
(rtos cnt)
With what you want. Look in the help to see how to code this. If you need more help let me know.
Tim
jondevries
2005-12-29, 10:05 PM
That worked.
Changed to (rtos cnt 2 0) and it always gives me decimal, rounded to 0 decimal places.
Thanks.
T.Willey
2005-12-29, 10:58 PM
You're welcome. I like being able to help people.
Tim
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.