Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Adding numbers, ingoring letters

  1. #1
    Certifiable AUGI Addict Robert.Hall's Avatar
    Join Date
    2004-07
    Location
    Detroit Michigan
    Posts
    2,510

    Default Adding numbers, ingoring letters

    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.

  2. #2
    100 Club timothyjturner's Avatar
    Join Date
    2005-09
    Location
    Columbus, OH
    Posts
    101

    Default Re: Adding numbers, ingoring letters

    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.
    Last edited by timothyjturner; 2005-10-13 at 02:51 PM.

  3. #3
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2002-12
    Location
    Brandon, Florida
    Posts
    687

    Default Re: Adding numbers, ingoring letters

    Here is a little ditty I wrote & may be of use to you.
    Attached Files Attached Files

  4. #4
    Certifiable AUGI Addict Robert.Hall's Avatar
    Join Date
    2004-07
    Location
    Detroit Michigan
    Posts
    2,510

    Default Re: Adding numbers, ingoring letters

    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.

  5. #5
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2002-12
    Location
    Brandon, Florida
    Posts
    687

    Default Re: Adding numbers, ingoring letters

    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"

  6. #6
    100 Club mathew.worland's Avatar
    Join Date
    2002-12
    Location
    Denver, CO USA
    Posts
    162

    Default Re: Adding numbers, ingoring letters

    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.

  7. #7
    Past Vice President peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu Hawaii
    Posts
    574

    Default Re: Adding numbers, ingoring letters

    try this routine
    Attached Files Attached Files

  8. #8
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043

    Default Re: Adding numbers, ingoring letters

    See if this one works for you.
    Attached Files Attached Files

  9. #9
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043

    Default Re: Adding numbers, ingoring letters

    Here is the revised version to work when there is a coma in the number.
    Attached Files Attached Files

  10. #10
    Certifiable AUGI Addict Robert.Hall's Avatar
    Join Date
    2004-07
    Location
    Detroit Michigan
    Posts
    2,510

    Default Re: Adding numbers, ingoring letters

    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.

    I also found using the undo command with this lisp routine will crash AutoCad.
    Last edited by Robert.Hall; 2005-10-18 at 12:37 PM.

Page 1 of 2 12 LastLast

Similar Threads

  1. Window tags with letters not numbers
    By jastuccio in forum ACA General
    Replies: 4
    Last Post: 2009-08-12, 05:17 PM
  2. Property Data Format for Numbers and Letters
    By fletch97 in forum ACA General
    Replies: 2
    Last Post: 2008-02-12, 10:36 PM
  3. Call out sections as numbers or letters?
    By crohloff.72988 in forum CAD Standards
    Replies: 9
    Last Post: 2006-06-26, 06:44 PM
  4. sequence of numbers and letters
    By hevgee in forum AutoLISP
    Replies: 3
    Last Post: 2006-03-17, 03:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •