Results 1 to 8 of 8

Thread: LISP for getting the Sum of Plant Quantity in a Text/MText String

  1. #1
    Member
    Join Date
    2013-02
    Posts
    49
    Login to Give a bone
    0

    Default LISP for getting the Sum of Plant Quantity in a Text/MText String

    Hi everyone!


    A little help please. Anyone here has a LISP for getting the Sum of Plant Quantity in a Text/MText String?


    Attached here are the samples for reference.

    I need a need a LISP to get a total quantity (numbers) of plants per species.


    for examples:

    G-OJ (1000nos) + G-OJ (1000nos) + G-OJ (3000nos) = G-OJ (5000nos)

    S-AJ (1000nos) + S-AJ (7000nos) + S_AJ (2000nos) = S-AJ (10000nos)


    Thanks! Hope someone can help me about this.

  2. #2
    Active Member
    Join Date
    2015-08
    Posts
    59
    Login to Give a bone
    0

    Default Re: LISP for getting the Sum of Plant Quantity in a Text/MText String

    Quote Originally Posted by rolandolramosjr360892 View Post
    Hi everyone!


    A little help please. Anyone here has a LISP for getting the Sum of Plant Quantity in a Text/MText String?


    Attached here are the samples for reference.

    I need a need a LISP to get a total quantity (numbers) of plants per species.


    for examples:

    G-OJ (1000nos) + G-OJ (1000nos) + G-OJ (3000nos) = G-OJ (5000nos)

    S-AJ (1000nos) + S-AJ (7000nos) + S_AJ (2000nos) = S-AJ (10000nos)


    Thanks! Hope someone can help me about this.
    I could not open your drawing because it was saved with a newer version. Thus I don't know if you want to sum blocks or attributes of blocks. Check out lee-mac.com .... I'm sure you will find some great help there to do the job.
    HTH, Steve

  3. #3
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,138
    Login to Give a bone
    0

    Default Re: LISP for getting the Sum of Plant Quantity in a Text/MText String

    It is not pretty... but it seems to work on single pieces of text/mtext

    P=

    Code:
    (defun C:AddPlants (/ intCount ssSelections)
     (if (setq ssSelections (ssget (list (cons 0 "text"))))
      (repeat (setq intCount (sslength ssSelections))
       (setq intCount     (1- intCount))
       (addplants (vlax-ename->vla-object (ssname ssSelections intCount)))
      )
     )
    )
    
    
    (defun AddPlants ( objSelection /
                       lstSublist
                       lstString1
                       lstString2
                       lstOfSublists
                       strValue                  
                       strString
                   )
     (and
      (setq strString    (vla-get-textstring objSelection))
      (setq lstString1   (csvstringtolist strString "="))
      (setq lstString2   (csvstringtolist (car lstString1) "+"))
      (setq lstOfSublists (mapcar 'breakup lstString2))
      (setq lstSublist    (car lstOfSublists))
      (setq strValue      (itoa (apply '+ (mapcar 'atoi (mapcar 'cadr lstOfSublists)))))
      (vla-put-textstring objSelection (strcat (car lstString1) " =  " (nth 0 lstSublist) strValue (nth 2 lstSublist)))
     )
    )
    
    (defun breakup (strString / blnText blnNumber intItem lstPart lstReturn)
     (setq blnText T blnNumber nil)
     (foreach intItem (vl-string->list strString)
      (if (and (> intItem 47) (< intItem 56))
       (if (not blnNumber)
        (setq blnNumber T
              lstReturn (cons lstPart lstReturn)
              lstPart   nil
        )
       )
       (if blnNumber
        (setq blnNumber nil
              lstReturn (cons lstPart lstReturn)
              lstPart   nil
        )
       )
      )
      (setq lstPart (cons intItem lstPart))
     )
     (setq lstReturn (cons lstPart lstReturn))
     (setq lstReturn (mapcar 'vl-list->string (reverse (mapcar 'reverse lstReturn))))
    )
    
    
    (defun CSVStringToList  (strText strChar / intPosition lstStrings)
     (while (setq intPosition (vl-string-search strChar strText 0))
      (setq lstStrings  (cons (substr strText 1 intPosition) lstStrings)
            strText     (substr strText (+ intPosition 1 (strlen strChar)))
      )
     )
     (if lstStrings
      (reverse (cons strText lstStrings))
      (list strText)
     )
    )
    
    (princ)
    AutomateCAD

  4. #4
    Member
    Join Date
    2013-02
    Posts
    49
    Login to Give a bone
    0

    Default Re: LISP for getting the Sum of Plant Quantity in a Text/MText String

    I could not open your drawing because it was saved with a newer version. Thus I don't know if you want to sum blocks or attributes of blocks. Check out lee-mac.com .... I'm sure you will find some great help there to do the job.
    HTH, Steve

    Hi Steve, thanks for the time. I reattached the file saved it to a lower version. Please have a look at it. Can you help me get the sum of number/quantity in a mtext string and not in a block.

    for example:

    S-AJ (1000nos) + S-AJ (7000nos) + S_AJ (2000nos) = S-AJ (10000nos), im using mtext because i cannot use a block.

  5. #5
    Member
    Join Date
    2013-02
    Posts
    49
    Login to Give a bone
    0

    Default Re: LISP for getting the Sum of Plant Quantity in a Text/MText String

    It is not pretty... but it seems to work on single pieces of text/mtext

    P=


    Hi Peter, thanks for the trying to help but your LISP is not working with me because i'm using MTEXT & not a BLOCK. I'm counting the quantity manually and input it to a call-out (MText) thats why i can't use a BLOCK in this matter. I'm reattached my file so you can take a look at it. Thanks for your time again.
    Attached Images Attached Images

  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: LISP for getting the Sum of Plant Quantity in a Text/MText String

    Perhaps like this, untested

    Code:
    (if 
    (setq sset (ssget "_X" (list (cons 0  "mtext" )(cons 1 "G-OJ (*,* G-OJ (*"))))
    (progn
      (setq fam "G-OJ"
    	sum 0)
    (while (setq en ( ssname sset 0))
    	     (setq elist (entget en))
      (setq txt (cdr (assoc 1 elist)))
      (setq pos (vl-string-search "G-OJ (" txt))
      (setq txt (substr txt (+ pos (strlen "G-OJ ("))))
      (setq txt (vl-string-subst "" "("  txt))
      (setq txt (vl-string-subst "" ")"  txt))
      (setq txt (vl-string-subst "" "}"  txt))
      (setq num (atoi txt))
      (setq sum (+ sum num))
      (ssdel en sset)
      )
      (alert (strcat "Sum of " fam " is : " (itoa sum) " plants"))
      )
    )
    Last edited by fixo; 2013-02-28 at 12:43 PM.

  7. #7
    Member
    Join Date
    2013-02
    Posts
    49
    Login to Give a bone
    0

    Default Re: LISP for getting the Sum of Plant Quantity in a Text/MText String

    (if
    (setq sset (ssget "_X" (list (cons 0 "mtext" )(cons 1 "G-OJ (*,* G-OJ (*"))))
    (progn
    (setq fam "G-OJ"
    sum 0)
    (while (setq en ( ssname sset 0))
    (setq elist (entget en))
    (setq txt (cdr (assoc 1 elist)))
    (setq pos (vl-string-search "G-OJ (" txt))
    (setq txt (substr txt (+ pos (strlen "G-OJ ("))))
    (setq txt (vl-string-subst "" "(" txt))
    (setq txt (vl-string-subst "" ")" txt))
    (setq txt (vl-string-subst "" "}" txt))
    (setq num (atoi txt))
    (setq sum (+ sum num))
    (ssdel en sset)
    )
    (alert (strcat "Sum of " fam " is : " (itoa sum) " plants"))
    )
    )


    Hi Fixo! Thanks for replying but can you please tell me how to use this one. I can only understand a simple LISP format. Please tell the steps on how to use this.


    Thank you again and for your time.

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

    Default Re: LISP for getting the Sum of Plant Quantity in a Text/MText String

    Wrap this code in defun as usual,
    like this not tested just from Notepad:

    Code:
    (defun C:Minfo (/ en elist fam num pos txt sum sset)
    (if 
    (setq sset (ssget "_X" (list (cons 0  "mtext" )(cons 1 "G-OJ (*,* G-OJ (*"))))
    (progn
      (setq fam "G-OJ"
    	sum 0)
    (while (setq en ( ssname sset 0))
    	     (setq elist (entget en))
      (setq txt (cdr (assoc 1 elist)))
      (setq pos (vl-string-search "G-OJ (" txt))
      (setq txt (substr txt (+ pos (strlen "G-OJ ("))))
      (setq txt (vl-string-subst "" "("  txt))
      (setq txt (vl-string-subst "" ")"  txt))
      (setq txt (vl-string-subst "" "}"  txt))
      (setq num (atoi txt))
      (setq sum (+ sum num))
      (ssdel en sset)
      )
      (alert (strcat "Sum of " fam " is : " (itoa sum) " plants"))
      )
    )
    (princ)
    )
    Save code as "Minfo.lsp"
    then load to AutoCAD or drop file on screen area
    then type in the command line: MINFO or minfo, no matters

Similar Threads

  1. Replies: 1
    Last Post: 2014-08-08, 05:20 PM
  2. LISP from AEC-Curve Text to MText or Regular Text
    By BoarsNest01 in forum AutoLISP
    Replies: 7
    Last Post: 2010-06-03, 02:46 PM
  3. Text align lisp - modify for mtext
    By beardking in forum AutoLISP
    Replies: 4
    Last Post: 2009-09-15, 08:01 PM
  4. Customize MTEXT sample string - MTJIGSTRING
    By Mike.Perry in forum AutoCAD Tips & Tricks
    Replies: 0
    Last Post: 2005-08-25, 10:16 PM
  5. Lisp to extract and add numbers from text/mtext string
    By cblendermann.91943 in forum AutoLISP
    Replies: 26
    Last Post: 2005-08-18, 03:25 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
  •