Results 1 to 10 of 10

Thread: TEXT QUANTITY

  1. #1
    Member
    Join Date
    2015-08
    Posts
    32
    Login to Give a bone
    0

    Default TEXT QUANTITY

    Is there any lisp to find entire drawing text and send the text quantity at one time to excel or CSV file?
    For example.
    SL No. TEXT QTY.
    1 3s 10
    2 5s 50
    3 100 15
    4 35 60

    Please advise me…

    Thanks in advance.

  2. #2
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Default Re: TEXT QUANTITY

    The ._dataextraction command will do it.
    R.K. McSwain | CAD Panacea |

  3. #3
    I could stop if I wanted to
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    0

    Default Re: TEXT QUANTITY

    Perhaps try my old Text Counter program.

  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: TEXT QUANTITY

    Found similar on what you need from oldies, eg

    Code:
    (defun c:tcsv ( / _group_and_sum alist en file i lst ss tmp x)
    ;; 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)
      (if (and(setq file (strcat (getvar "dwgprefix") "mytexts.csv"))
              (setq file(open file "w"))       
              (setq ss (ssget '((0 . "TEXT"))))
          )                 
        (progn
       
          (setq i -1)
          (repeat (sslength ss)
    	(setq en (ssname ss (setq i(1+ i)))
    	      alist (entget en)
    	    tmp (cons (cdr (assoc 1 alist)) 1)
    	      lst (cons tmp lst)))
          (setq lst (_group_and_sum lst))
          (setq i 0)
          (setq lst (mapcar '(lambda (x)(list (setq i(1+ i)) (car x)(cdr x))) lst))
          (setq lst (mapcar '(lambda (x)(mapcar 'vl-princ-to-string x)) lst))
          (write-line "SL No.,TEXT,QTY." file)
          (foreach n lst
    	(write-line (strcat (car n) ","(cadr n) ","(caddr n)) file)
    )
    
          (close file)
          )
        )
    
    (princ)  
    )

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

    Default Re: TEXT QUANTITY

    This code will do your example above.

    P=

    Code:
    (defun C:TextBOM (/ intCount  
                        intItem
                        lstEntity
                        lstOfSublists
                        lstReturn1 
                        lstReturn2                     
                        objSelection 
                        ssSelections 
                        strFileName
                        strFolder
                        strFullName
    
                        ; Local Functions
                        CompressList1
                        CountItemsInList
                        ListToCSVFile
                      )
     (vl-load-com)
    ; Local Functions
    
     (defun CompressList1 (lstAtoms / Atom1 lstAtoms2)
      (foreach Atom1 lstAtoms
       (if (not (member Atom1 lstAtoms2))
        (setq lstAtoms2 (cons Atom1 lstAtoms2))
       )
      )
      (vl-sort lstAtoms2 '<)
     )  
    
    
     (defun CountItemsInList (strItem lstItems / intCount strItem1)
      (setq intCount 0)
      (foreach strItem1 lstItems
       (if (= strItem1 strItem)
        (setq intCount (1+ intCount))
       )
      )
      (if intItem 
       (setq intItem (1+ intItem))
       (setq intItem 1)
      )
      (list (itoa intItem) strItem (itoa intCount))
     )
    
    
     (defun ListTOCSVFile (strFilename lstOfSublists strChar 
                           / 
                           strText 
                           strText2 
                           filData 
                           lstSublist)
      (setq filData (open strFileName "w"))
      (close filData)
      (setq filData (open strFileName "w"))
      (foreach lstSubList lstOfSublists 
       (setq strText (vl-princ-to-string (nth 0 lstSubList)))
       (if (and (= (type (cdr lstSublist)) 'LIST)
                (> (length lstSublist) 1)
           )
        (foreach strText2 (cdr lstSubList)
         (if (not strText2)
          (setq strText (strcat strText strChar ""))
          (setq strText (strcat strText strChar (vl-princ-to-string strText2)))
         )
        )
        (if (cdr lstSublist)
         (if (not (cdr lstSublist))
          (setq strText (strcat strText strChar ""))    
          (setq strText (strcat strText strChar (vl-princ-to-string (cdr lstSubList))))    
         )
        )
       )
       (write-line strText filData)
      )
      (close filData)
      (princ)
     )
    
    ; Base Function
     (if (setq ssSelections (ssget "x" (list (cons 0 "TEXT"))))
      (repeat (setq intCount (sslength ssSelections))
       (setq intCount      (1- intCount)
             objSelection  (vlax-ename->vla-object (ssname ssSelections intCOunt))
             lstReturn1     (cons (vla-get-textstring objSelection) lstReturn1)
       )    
      )
     )
     (if lstReturn1
      (progn
       (setq lstReturn1    (acad_strlsort lstReturn1)
             lstReturn2    (compresslist1 lstReturn1)
             lstOfSublists (mapcar '(lambda (X)(CountItemsInList X lstReturn1)) lstReturn2)
             strFolder     (getvar "dwgprefix")
             strFileName   (vl-filename-base (getvar "dwgname"))
             strFullName   (strcat strFolder strFileName ".csv")
       )
       (listtocsvfile strFullName lstOfSublists ",")
       (getstring "Press Enter")
       (command "notepad" strFullName)
      )
     )
    ) 
    (prin1)
    Attached Files Attached Files
    AutomateCAD

  6. #6
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: TEXT QUANTITY

    Hey Peter, long time no see!

    Just out of curiosity, why iterate the selection set via Repeat if you're going to convert each entity name to vla-object? Instead just call ssget from the test expression, and iterate the ActiveSelectionSet via vlax-for, no?

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

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

    Default Re: TEXT QUANTITY

    I have had problems with ActiveSelectionSet not resetting ... but the repeat method works good up to the limit of a short integer.

    I also like converting selection sets to lists and iterating.

    I have some code that uses the activeselectionset method and sometimes they get hung up.

    Old habits die hard.

    I have been using this method before the introduction of vlax-for so I just keep using it.

    It works...

    P=
    AutomateCAD

  8. #8
    I could stop if I wanted to
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    0

    Default Re: TEXT QUANTITY

    Quote Originally Posted by peter View Post
    I have had problems with ActiveSelectionSet not resetting ... I have some code that uses the activeselectionset method and sometimes they get hung up.
    Agreed - occassionally you receive an 'Automation Error. Calling method Clear of interface IAcadSelectionSet failed' error.

  9. #9
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: TEXT QUANTITY

    Interesting... Robert B originally educated me to the benefit of using ActiveSelectionSet, given that it can be iterated like an ActiveX Selection Set, despite not impacting the finite number of ActiveX Selection Sets. I do not recall experiencing such issues with it, so if/when I do, now I know...

    knowing-is-half-the-battle.jpg



    Cheers guys
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  10. #10
    Member
    Join Date
    2014-03
    Posts
    5
    Login to Give a bone
    0

    Default Re: TEXT QUANTITY

    Could any body help me to create a lisp for for sum text number before a specific alphabet character
    Example,

    5*M16*35
    2*M16*40
    4*M16*45

    First number indicates number of peices,So like that texts have so many in a drawing.
    I need a lisp to calculate each type how many have in that drawings and give me in csv file or in a table in the same drawing.
    Please help me any body.

    Thanks

Similar Threads

  1. 2014: material quantity
    By rmk in forum AutoCAD Civil 3D - General
    Replies: 1
    Last Post: 2015-02-06, 12:46 PM
  2. Replies: 7
    Last Post: 2013-03-19, 08:26 AM
  3. Quantity table
    By brainman1000 in forum AutoCAD Civil 3D - Pipes
    Replies: 3
    Last Post: 2009-04-17, 03:10 PM
  4. Quantity check
    By david_peterson in forum Revit Structure - General
    Replies: 2
    Last Post: 2006-10-30, 09:10 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
  •