anjan008 Posted March 3, 2014 Share Posted March 3, 2014 (edited) 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 4*M16*35 3*M16*40 6*M16*45 M16*35 M16*40 M16*45 result M16*35 =10 M16*40=6 M16*45=11 First number indicates number of pieces,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. If there is no number in front of M16..it should take it as 1 piece Please help me any body. Thanks Edited March 3, 2014 by anjan008 i want add extra information Quote Link to comment Share on other sites More sharing options...
Snownut Posted March 3, 2014 Share Posted March 3, 2014 Really would not matter what the 1st letter is, is there always a "*" between the number & 1st letter ? Quote Link to comment Share on other sites More sharing options...
anjan008 Posted March 3, 2014 Author Share Posted March 3, 2014 Thanks for reply No when number of pieces are 1 there will not be * if that number are more than 1 only it will indicate as 2*M16*35 So when there is no * In front of M16*35 it should take it as that is 1 Thanks Quote Link to comment Share on other sites More sharing options...
David Bethel Posted March 3, 2014 Share Posted March 3, 2014 For the VERY restricted format that you proposed ( contained in an ascii text file ) tsv.txt : [b][color=BLACK]([/color][/b]defun c:tsv [b][color=FUCHSIA]([/color][/b]/ file rf nl q v c fl[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq file [b][color=NAVY]([/color][/b]if dat_file [b][color=MAROON]([/color][/b]getfiled [color=#2f4f4f]"DATA File"[/color] dat_file [color=#2f4f4f]"txt"[/color] 2[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]getfiled [color=#2f4f4f]"DATA File"[/color] [color=#2f4f4f]"/acad/"[/color] [color=#2f4f4f]"txt"[/color] 2[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq dat_file file[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq rf [b][color=NAVY]([/color][/b]open [b][color=MAROON]([/color][/b]findfile file[b][color=MAROON])[/color][/b] [color=#2f4f4f]"r"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]setq nl [b][color=MAROON]([/color][/b]read-line rf[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]cond [b][color=MAROON]([/color][/b][b][color=GREEN]([/color][/b]= [color=#2f4f4f]""[/color] nl[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b][b][color=GREEN]([/color][/b]= [color=#2f4f4f]"M"[/color] [b][color=BLUE]([/color][/b]strcase [b][color=RED]([/color][/b]substr nl 1 1[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq q 1 v nl fl [b][color=BLUE]([/color][/b]if [b][color=RED]([/color][/b]assoc v fl[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]subst [b][color=PURPLE]([/color][/b]cons v [b][color=TEAL]([/color][/b]+ q [b][color=OLIVE]([/color][/b]cdr [b][color=GRAY]([/color][/b]assoc v fl[b][color=GRAY])[/color][/b][b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]assoc v fl[b][color=PURPLE])[/color][/b] fl[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]cons [b][color=PURPLE]([/color][/b]cons v q[b][color=PURPLE])[/color][/b] fl[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b][b][color=GREEN]([/color][/b]setq c 1[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]while [b][color=BLUE]([/color][/b]/= [color=#2f4f4f]"*"[/color] [b][color=RED]([/color][/b]substr nl c 1[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]setq c [b][color=RED]([/color][/b]1+ c[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq q [b][color=BLUE]([/color][/b]atoi [b][color=RED]([/color][/b]substr nl 1 [b][color=PURPLE]([/color][/b]1- c[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] v [b][color=BLUE]([/color][/b]substr nl [b][color=RED]([/color][/b]1+ c[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] fl [b][color=BLUE]([/color][/b]if [b][color=RED]([/color][/b]assoc v fl[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]subst [b][color=PURPLE]([/color][/b]cons v [b][color=TEAL]([/color][/b]+ q [b][color=OLIVE]([/color][/b]cdr [b][color=GRAY]([/color][/b]assoc v fl[b][color=GRAY])[/color][/b][b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]assoc v fl[b][color=PURPLE])[/color][/b] fl[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]cons [b][color=PURPLE]([/color][/b]cons v q[b][color=PURPLE])[/color][/b] fl[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]close rf[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1 fl[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] -David TSV.TXT Quote Link to comment Share on other sites More sharing options...
anjan008 Posted March 3, 2014 Author Share Posted March 3, 2014 no Luck All that text in autocad drawing only so why i need to create txt file first. Thanks Quote Link to comment Share on other sites More sharing options...
Snownut Posted March 3, 2014 Share Posted March 3, 2014 How is the text in the drawing ie: block names, plain text, mtext you need to gather the relevant text into a list somehow. Please be a lot more specific on just what you are starting with ! Quote Link to comment Share on other sites More sharing options...
anjan008 Posted March 3, 2014 Author Share Posted March 3, 2014 plain text and MTEXT Not required to be listed...if it can show in command area also will do my job. Drawing1.dwg Quote Link to comment Share on other sites More sharing options...
Snownut Posted March 3, 2014 Share Posted March 3, 2014 It appears in the drawing that all bolt information is on the "25_Bolt designation" layer and there is no other information on that layer, will this hold true. You need a method to build the list and it seems the layer is a good place to start. Quote Link to comment Share on other sites More sharing options...
anjan008 Posted March 3, 2014 Author Share Posted March 3, 2014 Yes that layer will only have bolt information Quote Link to comment Share on other sites More sharing options...
Snownut Posted March 3, 2014 Share Posted March 3, 2014 Then try this, the heavy lifting from David's code above is applied to the list of bolts from the drawing. (defun c:tsv (/ file rf nl q v c fl) (defun Mk_Bolt_Lst ( / ent lth sel txt boltl) (setq sel (ssget "_X" (list (cons 0 "TEXT") (cons 8 "25_Bolt designation"))) ) (repeat (setq lth (sslength sel)) (setq ent (ssname sel (setq lth (1- lth))) txt (list(cdr(assoc 1 (entget ent)))) boltL (append boltL txt) ) ) );defun (foreach nl (Mk_Bolt_Lst) ; David Bethal modified code (cond ((= "" nl)) ((= "M" (strcase (substr nl 1 1))) (setq q 1 v nl fl (if (assoc v fl) (subst (cons v (+ q (cdr (assoc v fl)))) (assoc v fl) fl) (cons (cons v q) fl)))) ((setq c 1) (while (/= "*" (substr nl c 1)) (setq c (1+ c))) (setq q (atoi (substr nl 1 (1- c))) v (substr nl (1+ c)) fl (if (assoc v fl) (subst (cons v (+ q (cdr (assoc v fl)))) (assoc v fl) fl) (cons (cons v q) fl)))))) (prin1 fl) (prin1) );defun The above worked fine on the drawing you posted. This is for Plain Text Only. Quote Link to comment Share on other sites More sharing options...
Snownut Posted March 3, 2014 Share Posted March 3, 2014 Sorry I know nothing about tables, maybe some else could chirp in on getting the resultant list in a table. Quote Link to comment Share on other sites More sharing options...
anjan008 Posted March 4, 2014 Author Share Posted March 4, 2014 Thanks for your effort.But it is working only in that drawing, In another with same type not working and also when it is having MTEXT also not working. thanks 22.dwg Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 4, 2014 Share Posted March 4, 2014 A couple of extra suggestions start with pick text or mtext return layer name for assoc 8 ssget this way its layer independant Use the text,mtext filter to make list obviously need 2 defuns do a if so use correct one for make list. Why not vlsort list do 1st pass if a-z or A-Z then add 1* to text this way one routine to add up text. Re to table if you make a list then I posted code example about a week ago on how to make a table from a list. Search for table example. Will try to find. Quote Link to comment Share on other sites More sharing options...
pBe Posted March 4, 2014 Share Posted March 4, 2014 (edited) > > (defun c:addme (/ trunc data ss i e match var opt fr sy) ;;; pBe04Mar2014 ;;; (defun trunc (s m [b]v w[/b]) (atoi (if m (substr s (+ 2 (vl-string-position [b]v[/b] s))) (substr s (+ 2 (vl-string-position [b] w[/b] s nil t))) ) ) ) [b](initget "Pack Bolt") (setq opt (getkword "\nChoose Option [Pack Washer/Bolt Information]")) (setq var (if (eq opt "Bolt") '(77 42 "*M##`**") '(80 45 "*PW-*mm") ) fr (car var) sy (cadr var))[/b] (if (setq data nil ss (ssget "_X" [b](list '(0 . "TEXT") (cons 1 (last var)) '(8 . "25_Bolt designation,7_Graphics") )[/b] ) ) (progn (repeat (setq i (sslength ss)) (setq e (ssname ss (setq i (1- i)))) (setq data (cons (cdr (assoc 1 (entget e))) data)) ) (setq data (vl-sort data '(lambda (b c) (cond ((< (setq d[b] (trunc b t fr sy )[/b]) [b](setq f (trunc c t fr sy)))[/b] t) ((= d f) (< [b](trunc b nil fr sy)[/b] [b](trunc c nil fr sy)[/b])) ) ) ) ) (While (setq a (car data)) (setq ref (substr a (1+ (vl-string-position[b] (car var)[/b] a)))) (setq match (vl-remove-if-not '(lambda (s) (wcmatch s (strcat "*" ref))) data ) ) (princ (strcat "\n" ref " = " (itoa (apply '+ (mapcar '(lambda (k) (if (zerop (atoi k)) 1 (atoi k) ) ) match ) ) ) ) ) (setq data (vl-remove-if '(lambda (y) (member y match)) data)) ) ) ) (princ) ) (vl-load-com) Edited March 5, 2014 by pBe CODE UPDATE/Bolt and Washers Quote Link to comment Share on other sites More sharing options...
anjan008 Posted March 4, 2014 Author Share Posted March 4, 2014 Thanks for suggestion, But i don't know how to do lisp program. Iam new to this. Could you please help me. One of our friend help me some extent. Thanks Quote Link to comment Share on other sites More sharing options...
anjan008 Posted March 4, 2014 Author Share Posted March 4, 2014 wow its working Thanks alot pBe... thanks for this help. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 4, 2014 Share Posted March 4, 2014 The example make a table for anyone interested as you will need to add this to make a table http://www.cadtutor.net/forum/showthread.php?84472-Entmake-Table-with-AutoLISP&highlight=Table. The code posted by Pbe creates a list called "Data" you can look at it by (nth 2 data) 3rd variable starts at 0 see code in example need to change name of list. If your lucky Pbe will add a table to his code. Quote Link to comment Share on other sites More sharing options...
anjan008 Posted March 4, 2014 Author Share Posted March 4, 2014 its working but to improve some more better. is it possible to give result like in order No need have this text in table format. like below result in command prompt is suitable for me M16*35 = 1 M16*45 = 1 M16*50 = 16 M16*55 = 6 M16*60 = 4 M16*65 = 126 M16*75 = 8 M16*70 = 2 M16*80 = 2 M24*75 = 32 M24*95 = 36 M24*100 = 12 M24*110 = 44 Sorry if i ask this is not possiable Thanks Quote Link to comment Share on other sites More sharing options...
pBe Posted March 4, 2014 Share Posted March 4, 2014 IT is possible, but you have to wait till tomorrow anjan008, i might even add a table to go with that Quote Link to comment Share on other sites More sharing options...
anjan008 Posted March 4, 2014 Author Share Posted March 4, 2014 Thanks so nice of you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.