Results 1 to 10 of 12

Thread: need lisp for sum text number after a specific alphabet character.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member
    Join Date
    2013-03
    Posts
    16
    Login to Give a bone
    0

    Default need lisp for sum text number after a specific alphabet character.

    hi everyone i am a new member
    i have file dwg that need to sum the number after letter
    FD 12.3
    FD 13.4
    FD 14
    BOX 125
    BOX 12
    FD 23.8 EBA 25.4
    LU 12.4 FD 23.7
    DU 45 FD 12
    etc...

    I want to get result
    FD=....
    EBA=...
    LU=...
    DU=...
    BOX=...

    And i need lisp code to sum its
    Because it's hard to calculate by calculator
    Anyone can help me
    Attached Files Attached Files

  2. #2
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: need lisp for sum text number after a specific alphabet character.

    Welcome on board, radosak
    Here is quick code example to group your formatted mtexts
    (just accordingly to your drawing)
    Select all mtexts by window then see a result
    Other than that you need to make by yoursef
    Code:
    (defun C:GPS(/ all dirty en _group_and_sum i ip item lb p1 p2 ss st string->list summary tmp TTC_MText_Clear uniques x)
      ;; helpers
     
      ;; by Tony Tanzillo  ;;
    (defun string->list (s delim)
       (read
          (vl-list->string
             (append
               '(40 34)        ;; add '("' to start
                (apply 'append
                   (subst 
                     '(34 34) 
                      (vl-string->list delim)
                      (mapcar 'list (vl-string->list s))
                   )
                )
               '(34 41)       ;; add '")" to end
             )
          )
       )
    )
     
         ;; Cleat MTEXT formatting  ;;
         ;; by VVA   ;;
        (defun TTC_MText_Clear(Mtext / Text Str) 
        (setq Text "") 
        (while(/= Mtext "") 
          (cond 
      ((wcmatch 
         (strcase 
           (setq Str 
            (substr Mtext 1 2))) 
                         "\\[\\{}`~]") 
       (setq Mtext(substr Mtext 3) 
             Text(strcat Text Str) 
       ); end setq 
      ); end condition #1 
      ((wcmatch(substr Mtext 1 1) "[{}]") 
        (setq Mtext 
         (substr Mtext 2)) 
      ); end condition #2 
      ( 
       (and 
       (wcmatch 
         (strcase 
           (substr Mtext 1 2)) "\\P") 
       (/=(substr Mtext 3 1) " ") 
        ); end and 
             (setq Mtext (substr Mtext 3) 
                   Text (strcat Text " ") 
             ); end setq 
       ); end condition #3 
      ((wcmatch 
         (strcase 
           (substr Mtext 1 2)) "\\[LOP]") 
        (setq Mtext(substr Mtext 3)) 
      ); end condition #4 
      ((wcmatch 
         (strcase 
           (substr Mtext 1 2)) "\\[ACFHQTW]") 
        (setq Mtext 
         (substr Mtext 
           (+ 2 
              (vl-string-search ";" Mtext)))) 
      ); end condition #5 
      ((wcmatch 
         (strcase (substr Mtext 1 2)) "\\S") 
        (setq Str(substr Mtext 3 (- (vl-string-search ";" Mtext) 2)) 
              Text(strcat Text (vl-string-translate "#^\\" " " Str)) 
              Mtext(substr Mtext (+ 4 (strlen Str))) 
       ); end setq 
       (print Str) 
      ); end condition #6 
      (T 
       (setq Text(strcat Text(substr Mtext 1 1)) 
             Mtext (substr Mtext 2) 
       ) 
      ); end condition #7 
          ); end cond 
        ); end while 
      Text 
    ); end of TTC_MText_Clear
     
    ;; fixo () 2010 * all rights released      ;;
    ;; arguments: lst - list of pairs kind of:   
    ;;(setq lst '(("a" . 12)("b" . 12)("a" . 26) ("d" . 23)("b" . 20)("a" . 24) ("c" . 12)("d" . 27)))..etc...;;
    (defun _group_and_sum (lst / all i lb summary tmp uniques)
      (setq all (mapcar 'car lst)
     uniques nil
      ) ;_ end of setq
      (while (car all)
        (setq uniques (cons (car all) uniques))
        (setq all (vl-remove-if '(lambda (x) (eq x (car all))) all))
      ) ;_ end of while
      (setq i   -1
     tmp nil
      ) ;_ end of setq
      (repeat (length uniques)
        (setq tmp
        (cons
          (setq lb (nth (setq i (1+ i)) uniques))
          (apply '+
          (mapcar
            'cdr
            (vl-remove-if-not '(lambda (x) (eq (car x) lb)) lst)
          ) ;_ end of mapcar
          ) ;_ end of apply
        ) ;_ end of cons
        ) ;_ end of setq
        (setq summary (cons tmp summary))
      ) ;_ end of repeat
      (vl-sort summary '(lambda (a b) (< (car a) (car b))))
    ) ;_ end of defun
    ;;    Usage :(_group_and_sum lst) ;;
     
    ;;    main part    ;;
     
      (princ "\Select table text by window selection")
      (setq p1 (getpoint "\nSpecify the first corner point: >> ")
     p2 (getcorner p1 "\nSpecify the opposite corner point: >> ")
     )
      (setq ss (ssget "W" (list (car p1)(cadr p1)) (list (car p2)(cadr p2)) (list (cons 0 "*TEXT")))
     i  -1
      )
      (repeat (sslength ss)
        (setq en   (ssname ss (setq i (1+ i)))
       ip   (cdr (assoc 10 (entget en)))
       st  (cdr (assoc 1 (entget en))))
       ;st (substr st (+ 2 (vl-string-position (ascii";") st ))(vl-string-position (ascii";") st ))
       (if (eq "MTEXT" (cdr (assoc 0 (entget en))))(setq  st (TTC_MText_Clear st)))
        (setq tmp (mapcar '(lambda (x)(if (zerop (atof x)) x (atof x))) (string->list st " ")))
    (while (cadr tmp)
      (setq item (cons (car tmp)(cadr tmp)))
      (setq dirty (cons item dirty))
      (setq tmp (cddr tmp))))
     (setq summary    (_group_and_sum dirty))
      (print summary)
      (textscr); display result
     
    ;;   --- do whatever you want with 'summary' here ---  ;;
     
    (princ)
      )
    (prompt "\n\t*** Type GPS to execute...")
    (prin1)
    Last edited by fixo; 2013-04-02 at 05:29 AM.

  3. #3
    Member
    Join Date
    2013-03
    Posts
    16
    Login to Give a bone
    0

    Default Re: need lisp for sum text number after a specific alphabet character.

    WOW AMAZING !!!
    YOU ARE GOOD AT WRITE CODE LISP

    THANK YOU VERY MUCH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  4. #4
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: need lisp for sum text number after a specific alphabet character.

    Glad to help
    Cheers

  5. #5
    Member
    Join Date
    2013-03
    Posts
    16
    Login to Give a bone
    0

    Default Re: need lisp for sum text number after a specific alphabet character.

    BUT WHEN I OPEN NEW DRAWING OR ADD SOME TEXT. IT'S NOT WORKING.

    Command: GPS Select table text by window selection
    Specify the first corner point: >>
    Specify the opposite corner point: >> ; error: bad argument type: numberp: nil

    AND IT DOESN'T SUM INCLUDE DECIMAL. LIKE 50.20 30.34 OR ETC..

    COULD YOU HELP ME PLEASE?
    Last edited by radosak368138; 2013-03-31 at 05:02 PM.

  6. #6
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: need lisp for sum text number after a specific alphabet character.

    You've used formatted mtext in your drawing,
    so copy any mtext from plain table and change them
    in text editor

  7. #7
    I could stop if I wanted to
    Join Date
    2005-06
    Location
    CORDOBA-ARGENTINA
    Posts
    275
    Login to Give a bone
    0

    Default Re: need lisp for sum text number after a specific alphabet character.

    You want to sum what NUMBER , the same to all MTEXT? ,

Similar Threads

  1. Replies: 2
    Last Post: 2014-03-04, 03:43 PM
  2. View Title: Label Read first character of Detail Number Only?
    By BSaunders in forum Revit Architecture - General
    Replies: 2
    Last Post: 2010-10-20, 11:24 PM
  3. Prefix Filenames with Project Number - Change Character
    By bradg in forum Project Navigator
    Replies: 0
    Last Post: 2008-11-13, 09:08 PM
  4. Replies: 13
    Last Post: 2007-03-19, 11:37 AM

Posting Permissions

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