egilim123 Posted September 1, 2022 Posted September 1, 2022 hi everyone i want to use find and replace sezrch results as an output for excel,word.etc. is there any lisp for this? thanks Quote
Emmanuel Delay Posted September 2, 2022 Posted September 2, 2022 Are you only looking for Mtext elements? Or could you list what kind of things you're looking for? Quote
egilim123 Posted September 2, 2022 Author Posted September 2, 2022 yes as shown in the circle i want to take the output of all search results so ican filter and count them in excel Quote
Steven P Posted September 2, 2022 Posted September 2, 2022 As a start, MHUPPs answer here yesterday is a good starting point, selecting all text containing your text string. I reckon it can be changed easily enough to copy the texts to clipboard and so you can paste the texts to excel 1 Quote
Steven P Posted September 2, 2022 Posted September 2, 2022 Adding this at the end oh MHUPPS code above will create a string with all the texts ...... (prompt (strcat "\n" txt "Not Found in Drawing")) ) ;;;;NEW PART HERE;;;;; (setq Selectedtexts nil) (setq acount 0) (while ( < acount (sslength ss)) (if (= nil Selectedtexts) (setq Selectedtexts (cdr (assoc 1 (entget (ssname ss acount))))) (setq Selectedtexts (strcat Selectedtexts ", " (cdr (assoc 1 (entget (ssname ss acount)))))) ) (setq acount (+ acount 1)) ) ; end while (princ Selectedtexts) ;;;CONTINUE WITH OLD LISP HERE;;;;; (princ) ) I have a line above (setq Selectedtexts (strcat Selectedtexts ", " (cdr (assoc 1 (entget (ssname ss acount)))))) which separates the text strings with a comma, you can change this to whatever you want. The above is to show how you can collate the text strings you searched for. If it was me I would either use LISP and AutoCAD to create the report you want (always better I think to avoid one companies software trying to use and talk to another), or to save the output as a CSV file and import that into Excel to filter and count as you want. If you want to keep it simple there is a line I can add to copy this to clipboard. Recently there was another post about writing directly to Excel, BigAl I think had a solution if you want to do that, he might be along later with words of wisdom, or you can look through recent threads and find it out, have a go and see what you can do. See if this works for you and what you want to do from here. 1 Quote
egilim123 Posted September 2, 2022 Author Posted September 2, 2022 thanks all for your interest , i tried mhupp s code but it only hıghlıghts the text i search and i tried Stevens additonal codes on mhupps code and its still the same it choses and highlights all the text i search but after i ctrl+c all the chosen things and i ctrl+v it on the excel they dont come as a text but they come as jpeg and i cannot use them in a excell cell Quote
egilim123 Posted September 2, 2022 Author Posted September 2, 2022 actually what i really need is this; there is a drawing from previous personel in our company , in his autocad drawing for example there are 30 different diameter pipes and he has written the lenghts and diameters of 30 pipes near the pipe drawings like; pipe1 Q40mm and length 30cm pipe2 Q50mm and length 25cm pipe3 Q32mm and length 40cm pipe4 Q40mm and length 35cm.................... ................................................ so it goes on like this and i want to select for example 40mm diameter pipe texts and take them out to excel cells to automaticaly write the lenghts of all diameters and take the sum of them i hope i could make myself clear thanks again Quote
Steven P Posted September 2, 2022 Posted September 2, 2022 In my code, run it and if you look in the command line, the texts are pasted there, and you can copy them from that. I didn't take it any further than that, suspecting that you were wanting to do something else with the text there might be a better solution. Do you need to paste the texts and distances into Excel? And are all the texts in the format diameter-distance cm, if so you can do more processing with the LISP before it goes to excel to make it simpler, or you can just get the sum in CAD, for example in an alert box Quote
egilim123 Posted September 2, 2022 Author Posted September 2, 2022 @Steven P can you please send your lisp with addiotıon to mhupps please and what should i type to run the lisp please thank you Quote
egilim123 Posted September 2, 2022 Author Posted September 2, 2022 @Steven Pi tried your code with adding it to mhupps , i typed st as the command, when i run the lisp it asks ,search for the text i write for example 32 and it selects all the 32's and they also shown in the command line and i can copy them from the command lines and i copied them to excel cells Quote
egilim123 Posted September 2, 2022 Author Posted September 2, 2022 thank you very much so now the only thing left is to seperate them to different excel cells because this way i can only take them to 1 excel cell but i need to take all different lengths to different cells so that i can sum up them easily. thanks very much @Steven P and to everyone involved Quote
Steven P Posted September 2, 2022 Posted September 2, 2022 I think if I put in a copy to clipboard at the end of what I did, I can make it go to different cells, will try it shortly and let you know Quote
Steven P Posted September 2, 2022 Posted September 2, 2022 Got to love end of week team meetings, try this: This should copy the selected texts to the clipboard, paste into excel the usual way, paste, ctr+V, whatever, each selected text is on a new line in excel. (defun SetClipBoardText ( MyText / htmlfile result ) (vlax-invoke (vlax-get (vlax-get (setq htmlfile (vlax-create-object "htmlfile")) 'ParentWindow) 'ClipBoardData) 'setData "Text" Mytext) (vlax-release-object htmlfile) (princ) ) (defun C:ST (/ txt ss typ) (if (eq (setq txt (strcase (getstring "\nSearch for Text [Area]: "))) "");hit enter for defult options. (setq txt "AREA") ;set defult search options here ) (if (setq ss (ssget "_X" (list '(0 . "MTEXT,TEXT,MULTILEADER,DIMENSION") (cons 410 (getvar 'ctab))))) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (setq typ (cdr (assoc 0 (entget ent)))) (cond ((member typ '("TEXT" "MTEXT" "MULTILEADER")) (setq obj (vlax-ename->vla-object ent)) ;convert to val-object (if (vl-string-search txt (strcase (vlax-get obj 'TextString))) (progn) ;if found leave in selection set (ssdel ent ss) ;if not found in string remove from selection s ) ) ((eq typ "DIMENSION") (setq obj (vlax-ename->vla-object ent)) ;convert to val-object (if (vl-string-search txt (strcase (vlax-get obj 'TextOverride))) (progn) ;if found leave in selection set (ssdel ent ss) ;if not found in string remove from selection s ) ) ) ) ) (if (> (sslength ss) 1) ;if anything is still in the selection set (progn (prompt (strcat "\n" (itoa (sslength ss)) " Entitys containing \"" txt "\"")) (sssetfirst nil ss) ) (prompt (strcat "\n" txt "Not Found in Drawing")) ) (setq Selectedtexts nil) (setq acount 0) (while ( < acount (sslength ss)) (if (= nil Selectedtexts) (setq Selectedtexts (cdr (assoc 1 (entget (ssname ss acount))))) (setq Selectedtexts (strcat Selectedtexts (chr 10) (cdr (assoc 1 (entget (ssname ss acount)))))) ) (setq acount (+ acount 1)) ) ; end while (SetClipBoardText Selectedtexts) (princ Selectedtexts) (princ) ) 1 Quote
BIGAL Posted September 3, 2022 Posted September 3, 2022 (edited) Why not get the lisp to do all the work if you make a list of all text can sort, then group by dia into sub lists, then get length and add up so output to excel as result required. For me working on smarter excel defuns including write direct to excel say the results in this case. 40dia 1050 30dia 935 25dia 1234 Edited September 3, 2022 by BIGAL 2 Quote
mhupp Posted September 3, 2022 Posted September 3, 2022 I was going a step further and keep it in the family by just output to a table inside AutoCAD. but would really need a sample drawing. 2 Quote
egilim123 Posted September 3, 2022 Author Posted September 3, 2022 hi again everyone, i tried @Steven Pnew code and yes it worked for me, its indeed very good , it will do my job , thanks very much again @Steven P, i wish nice weekends for all and hope to write you again. 1 Quote
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.