Jump to content

autocad lisp find and replace search results output


egilim123

Recommended Posts

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

 

 

  • Like 1
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)
)

 

 

  • Like 1
Link to comment
Share on other sites

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 by BIGAL
  • Like 2
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...