Results 1 to 8 of 8

Thread: Summation of numbers with prefix alphabets not working.

  1. #1
    Login to Give a bone
    0

    Default Summation of numbers with prefix alphabets not working.

    Dear All,

    I got a lisp code that is well working for summation of number with suffix alphabets, but not working for numbers with prefix alphabets. Please have a look on attachments and below lisp code.

    Code:
    (defun C:ADCC (/ cpent elist en ip newtxt pt ss sum sumtxt txt)
    (princ "\n\t\t>>>  Select text to get summ >>>")
    (if
    ;;select texts/mtexts on screen :
    (setq ss (ssget '((0 . "*TEXT"))))
    ;; if selected then :
    (progn
      ;; store the first text entity for using 'em further :
    (setq cpent (ssname ss 0))
      ;; set initial sum to zero :
      (setq sum 0.)
      ;; loop trough selected texts/mtexts :
      (while
        ;; get the first text in selection :
        (setq en (ssname ss 0))
        ;; get entity list of them :
        (setq elist (entget en))
        ;; get the textstring by key 1 from entity list :
        (setq txt (cdr (assoc 1 elist)))
        ;; create output string :
        (setq sumtxt
                       ;; concatenate strings :
                       (strcat
                         ;; convert digits to string :
                         (rtos
                           ;; add to summ the digital value of text :
                           (setq sum (+ (atof txt) sum))
                           ;; 2 is for metric units (3 for engineering) :
                           2
                           ;; set precision by current :
                           (getvar "dimdec")))
                      )
        ;; delete entity from selection set :
        (ssdel en ss)
        )
      ;; display message in the command line:
      (princ (strcat "\nSumm=" sumtxt))
      (setq pt (getpoint "\nSpecify the new text location: "))
      ;; get the insertion point of stored entity :
      (setq ip (cdr (assoc 10 (entget cpent))))
      ;; copy text entity to the new destination point :
      (command "_copy" cpent "" ip pt)
      ;; get the last created entity :
      (setq newtxt (entlast))
      ;; get entity list of them :
      (setq elist (entget newtxt))
      ;; modify entity list with new text string :
      (entmod (subst (cons 1 sumtxt)(assoc 1 elist) elist))
      ;; update changes :
      (entupd newtxt)
      )
    )
    (princ)
      )
    (princ "\nStart command with STX...")
    (princ)
    Attached Files Attached Files

  2. #2
    I could stop if I wanted to
    Join Date
    2002-08
    Posts
    231
    Login to Give a bone
    0

    Default Re: Summation of numbers with prefix alphabets not working.

    Hi,

    You can try to change the line
    Code:
    (setq sum (+ (atof txt) sum))
    by this:
    Code:
    (setq sum (+ (atof (vl-list->string (vl-remove-if-not '(lambda (x) (member x '(46 48 49 50 51 52 53 54 55 56 57))) (vl-string->list txt)))) sum))
    BE CAREFUL: Keep all number in the string and point (.0123456789)

    For exemple: if text is
    "1-Hello. Keep number: 666.66 no good!"
    return -> 1.666 and not 666.66 (1 before "-Hello" and . after) and (atof "1.666.66") return 1.666

  3. #3
    Login to Give a bone
    0

    Default Re: Summation of numbers with prefix alphabets not working.

    Dear Sir,

    Thank you so much, Its working well

  4. #4
    Login to Give a bone
    0

    Default Re: Summation of numbers with prefix alphabets not working.

    Dear Sir,

    Can we have a multiplication factor for outcome with "0.9".? Thank you in advance.

  5. #5
    I could stop if I wanted to
    Join Date
    2002-08
    Posts
    231
    Login to Give a bone
    0

    Default Re: Summation of numbers with prefix alphabets not working.

    Quote Originally Posted by brahmanandam.thadikonda762224 View Post
    Dear Sir,

    Can we have a multiplication factor for outcome with "0.9".? Thank you in advance.
    Insert at this a line
    Code:
      ;; display message in the command line:
      (princ (strcat "\nSumm=" sumtxt))
    became
    Code:
      ;; display message in the command line:
      (setq sum (* sum 0.9))
      (princ (strcat "\nSumm=" sumtxt))

  6. #6
    Login to Give a bone
    0

    Default Re: Summation of numbers with prefix alphabets not working.

    Quote Originally Posted by Bruno.Valsecchi View Post
    Insert at this a line
    Code:
      ;; display message in the command line:
      (princ (strcat "\nSumm=" sumtxt))
    became
    Code:
      ;; display message in the command line:
      (setq sum (* sum 0.9))
      (princ (strcat "\nSumm=" sumtxt))
    Dear Sir,

    I have inseted your code in original lisp code. But not working with 0.9 multification factor.
    (defun C:9M (/ cpent elist en ip newtxt pt ss sum sumtxt txt)
    (princ "\n\t\t>>> Select text to get summ >>>")
    (if
    ;;select texts/mtexts on screen :
    (setq ss (ssget '((0 . "*TEXT"))))
    ;; if selected then :
    (progn
    ;; store the first text entity for using 'em further :
    (setq cpent (ssname ss 0))
    ;; set initial sum to zero :
    (setq sum 0.)
    ;; loop trough selected texts/mtexts :
    (while
    ;; get the first text in selection :
    (setq en (ssname ss 0))
    ;; get entity list of them :
    (setq elist (entget en))
    ;; get the textstring by key 1 from entity list :
    (setq txt (cdr (assoc 1 elist)))
    ;; create output string :
    (setq sumtxt
    ;; concatenate strings :
    (strcat
    ;; convert digits to string :
    (rtos
    ;; add to summ the digital value of text :
    (setq sum (+ (atof txt) sum))
    ;; 2 is for metric units (3 for engineering) :
    2
    ;; set precision by current :
    (getvar "dimdec")))
    )
    ;; delete entity from selection set :
    (ssdel en ss)
    )
    ;; display message in the command line:
    (setq sum (* sum 0.9))
    (princ (strcat "\nSumm=" sumtxt))
    (setq pt (getpoint "\nSpecify the new text location: "))
    ;; get the insertion point of stored entity :
    (setq ip (cdr (assoc 10 (entget cpent))))
    ;; copy text entity to the new destination point :
    (command "_copy" cpent "" ip pt)
    ;; get the last created entity :
    (setq newtxt (entlast))
    ;; get entity list of them :
    (setq elist (entget newtxt))
    ;; modify entity list with new text string :
    (entmod (subst (cons 1 sumtxt)(assoc 1 elist) elist))
    ;; update changes :
    (entupd newtxt)
    )
    )
    (princ)
    )
    (princ "\nStart command with STX...")
    (princ)

  7. #7
    I could stop if I wanted to
    Join Date
    2002-08
    Posts
    231
    Login to Give a bone
    0

    Default Re: Summation of numbers with prefix alphabets not working.

    Sorry for my mistake, I have not tested my answer.
    Is must be:
    (setq sumtxt (rtos (* sum 0.9) 2 (getvar "DIMDEC)))

  8. #8
    Login to Give a bone
    0

    Default Re: Summation of numbers with prefix alphabets not working.

    Thank you Sir

Similar Threads

  1. Replies: 3
    Last Post: 2018-09-19, 04:32 AM
  2. working with different project numbers
    By jagostinho in forum BIM Management - General
    Replies: 9
    Last Post: 2014-03-27, 06:50 PM
  3. Placing alphabets automatically in sequential order
    By Wish List System in forum AutoCAD Wish List
    Replies: 2
    Last Post: 2012-08-14, 06:22 AM
  4. Summation
    By wfrst2008 in forum Revit Structure - General
    Replies: 3
    Last Post: 2007-09-13, 08:24 PM
  5. Summation of Mass Properties in the BOM
    By inventor.wishlist1738 in forum Inventor Wish List
    Replies: 0
    Last Post: 2006-09-19, 09:41 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
  •