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.
|
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.
R.K. McSwain | CAD Panacea |
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) )
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)
AutomateCAD
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
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
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
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