Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: Lisp to extract and add numbers from text/mtext string

  1. #1
    Member
    Join Date
    2005-08
    Posts
    40
    Login to Give a bone
    0

    Angry Lisp to extract and add numbers from text/mtext string

    Good day,
    I am trying to automate plant counting in my drawings. Currently we are using only a few plant blocks to show all the plants in our drawings. So Bcount cannot be used for the purpose of counting plants. The labels for the plants define which symbol is what type of plant. For example the plants labeled JH , AR and JPP are all using the same block in the drawing. In order to get a total for each plan I have to go through the whole drawing and manually add all the JH, AR and JPP labels and then input the total for each plant type into the landscaping table.. Typically a label would read: 4 JH, 15 AR, 1 JPP etc...
    The labels can be either text or Mtext format.
    I am looking for a routine that would , after user input, add up the numerical values of the labels with the same "text" component (JH , AR, JPP in this example)
    So, if I had 3 clusters of JH's, 5JH, 3 JH and 8 JH the lisp would ask for the plant name "JH", in this example, then the user would be asked to select the text strings, and should select all the labels in the drawing, the routine would then filter out the ones that have the "JH" string (and only JH, since other plants could be labeled "JHP" which should not be added to the JH's) then would return : total JH = 16.
    The plant labels are on one layer, so perhaps a different way to do the adding would be to select all the labels for all the plants and the routine would find each type of label (JH, JHP, AR etc) and add the associated numerical values and create a list of all the plants and their totals......
    Hope this long explanation is clear enough .
    Let me know if any routine is available or if clarifications are needed.
    Any suggestion on how to solve this differently would be welcome as well

    Thank you for your time

    Cord B.

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,103
    Login to Give a bone
    0

    Default Re: Lisp to extract and add numbers from text/mtext string

    Cord,

    Your explanation sounds clear to me. But I have one question. Why not use a different block name for each plant type? You could use the same geometry in each block, essentially having three different blocks, but containing the exact same geometry.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #3
    Member
    Join Date
    2005-08
    Posts
    40
    Login to Give a bone
    0

    Default Re: Lisp to extract and add numbers from text/mtext string

    I wish I could make all the rules ... but I would have to straighten out a whole bunch of habits etc and I am the new guy, so go with the flow applies and I am just trying to help out with the current state of affairs.
    I will try to push for a use of multiple blocks but that could take a while to get everyone involved retrained etc, block library expanded and so on...

    Cord B.

  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: Lisp to extract and add numbers from text/mtext string

    Hi Cord B.!

    Try this one
    This routine counts all blocks JH, JHR and AR
    and put result in Excel table

    Thank you

    f.
    Attached Files Attached Files

  5. #5
    I could stop if I wanted to scwegner's Avatar
    Join Date
    2004-12
    Location
    Minneapolis, MN
    Posts
    449
    Login to Give a bone
    0

    Default Re: Lisp to extract and add numbers from text/mtext string

    It's not perfect, but here's something I threw together. It prompts for a string and then appends a number to all attributes with that string. Hope this is what you wanted. It's missing an error handler and a few other things but it works. It's case sensitive too...

    Simon
    Attached Files Attached Files

  6. #6
    Member
    Join Date
    2005-08
    Posts
    40
    Login to Give a bone
    0

    Default Re: Lisp to extract and add numbers from text/mtext string

    This works nicely with blocks but not with text string, unfortunately I cannot use block counts since we do not use a specific block for each type of plant...
    Thanx for the helping hand

    Quote Originally Posted by fixo
    Hi Cord B.!

    Try this one
    This routine counts all blocks JH, JHR and AR
    and put result in Excel table

    Thank you

    f.

  7. #7
    Member
    Join Date
    2005-08
    Posts
    40
    Login to Give a bone
    0

    Default Re: Lisp to extract and add numbers from text/mtext string

    I think that your routine adds a number to a block attribute correct?
    I am looking for a routine that would add up the value that are shown together with a given text string....text and/or Mtext.

    Cord B.



    Quote Originally Posted by scwegner
    It's not perfect, but here's something I threw together. It prompts for a string and then appends a number to all attributes with that string. Hope this is what you wanted. It's missing an error handler and a few other things but it works. It's case sensitive too...

    Simon

  8. #8
    I could stop if I wanted to scwegner's Avatar
    Join Date
    2004-12
    Location
    Minneapolis, MN
    Posts
    449
    Login to Give a bone
    0

    Default Re: Lisp to extract and add numbers from text/mtext string

    Quote Originally Posted by cblendermann.91943
    I think that your routine adds a number to a block attribute correct?
    I am looking for a routine that would add up the value that are shown together with a given text string....text and/or Mtext.

    Cord B.
    My bad, I misunderstood. Try this then. It'll just prompt for a string and return the number of instances in text, mtext, or attributes.
    Attached Files Attached Files
    Last edited by scwegner; 2005-08-15 at 06:58 PM.

  9. #9
    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 to extract and add numbers from text/mtext string

    Quote Originally Posted by cblendermann.91943
    This works nicely with blocks but not with text string, unfortunately I cannot use block counts since we do not use a specific block for each type of plant...
    Thanx for the helping hand
    Sorry I don't understand your task in full...

    Thank you

    f.

  10. #10
    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 to extract and add numbers from text/mtext string

    Hi again

    How about this routine?

    Thank you

    f.

    Code:
    ; Convert list to string with delimeter	;
    
    (defun strfil (lst)
      (setq strk "")
      (while lst
      (setq tmp (strcat (car lst) ","))
      (setq strk (strcat strk tmp )
    	lst (cdr lst)))
      (vl-string-right-trim "," strk))
    
    ;;  Groups elements in list by test
    
    (defun tracks (test lst)
    (apply 'append (mapcar '(lambda (x)
    (if (wcmatch x test)(list  x ))) lst)))
    
    
    ;;;(setq a (vlax-ename->vla-object (car (entsel))))
    
    (defun C:CountPlants (/		 acsp	    adoc       cl
    		      cn	 cnt	    count_list data_table
    		      header	 hgt	    lgh	       patt
    		      snip	 sub_header tbl_obj    tmp_count
    		      total_summ tot_row    tpt	       txt_list
    		      type_list
    		     )
      (vl-load-com)
      (setq	adoc (vla-get-activedocument
    	       (vlax-get-acad-object)
    	     )
    	acsp (vla-get-block
    	       (vla-get-activelayout adoc)
    	     )
      )
      (setq	type_list '("AR" "JH" "JHR");change by suit
    	type_list (mapcar (function (lambda (x)
    				      (strcat "*" x)
    				    )
    			  )
    			  type_list
    		  )
      )
      (vlax-for a acsp
        (if	(and (wcmatch (vla-get-objectname a) "AcDbText,AcDbMText")
    	     (wcmatch (vla-get-textstring a) (strfil type_list))
    	)
          (setq txt_list (cons (vla-get-textstring a) txt_list))
        )
      )
      (repeat (length type_list)
        (setq patt (car type_list))
        (setq snip (tracks patt txt_list))
        (setq tmp_count (list (car snip) (itoa (length snip))))
        (setq count_list (cons tmp_count count_list))
        (setq type_list (cdr type_list))
      )
      (setq count_list (reverse count_list))
      (setq	total_summ
    	 (itoa (apply '+ (mapcar 'atoi (mapcar 'cadr count_list)))
    	 )
      )
      (setq cnt 1)
      (foreach i count_list
        (setq i (append (list (itoa cnt)) i))
        (setq data_table (cons i data_table))
        (setq cnt (1+ cnt))
      )
      (setq data_table (reverse data_table))
      (setq tot_row (list "Total" "-" total_summ));change by suit
      (setq data_table (append data_table (list tot_row)))
    
      (setq header (getstring t "\n	Table Header Text:\n"))
      (initget 1)
      (setq tpt (getpoint "\nTable Insertion Point:	\n"))
      (initget 1)
      (setq hgt (getdist "\nRow Height:	\n"))
      (initget 1)
      (setq lgh (getdist "\nColumn Length:	\n"))
      
      (setq sub_header '("##" "Plant Label" "Quantity"));change by suit
    
      (setq	tbl_obj	(vla-addtable
    		  acsp
    		  (vlax-3d-point tpt)
    		  (+ (length data_table) 2)
    		  (length sub_header)
    		  hgt
    		  lgh
    		)
      )
      (vla-settext tbl_obj 0 0 header)
      (vla-setcellalignment tbl_obj 0 0 acmiddlecenter)
      (vla-setcelltextheight tbl_obj 0 0 250.);header text height-change by suit
      (setq cn 0)
      (foreach item	sub_header
        (vla-settext tbl_obj 1 cn item)
        (vla-setcellalignment tbl_obj 1 cn acmiddlecenter)
        (vla-setcelltextheight tbl_obj 1 cn 225.);sub_header text height-change by suit
        (setq cn (1+ cn))
      )
      (setq cl 2)
      (setq cn 0)
      (foreach a data_table
        (foreach b a
          (vla-settext tbl_obj cl cn b)
          (vla-setcellalignment tbl_obj cl cn acmiddlecenter)
          (vla-setcelltextheight tbl_obj cl cn 200.);cell text height-change by suit
          (setq cn (1+ cn))
        )
        (setq cl (1+ cl))
        (setq cn 0)
      )
      (princ)
    )
    (C:CountPlants)
    (princ)

Page 1 of 3 123 LastLast

Similar Threads

  1. List for Sum of first numbers in text string
    By kumar2589 in forum AutoLISP
    Replies: 11
    Last Post: 2014-08-28, 08:03 AM
  2. Replies: 1
    Last Post: 2014-08-08, 05:20 PM
  3. Switch places on numbers in a text with a LISP routine?
    By kristian380590 in forum AutoLISP
    Replies: 12
    Last Post: 2013-05-27, 12:24 PM
  4. Replies: 7
    Last Post: 2013-03-19, 08:26 AM
  5. Replies: 1
    Last Post: 2007-01-26, 06:21 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
  •