Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Find and replace everything after a character

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
atuckerJKU9U
728 Views, 6 Replies

Find and replace everything after a character

I've been googling this for an hour, and can find people having the issue, but never a solution.   The consensus is that wildcards work great for find, but not for replace.  What I want to do seems simple.  I have lots of text objects (mleaders) that read something like the following: 

100 MFR; instructions on what to do with the hundred

 

All of the texts are completely different except for the semicolon.  The items before the semicolon are always a number and a text, but the number of characters varies.  I want to delete the semicolon and everything after it, preserving the part before the semicolon.  Is this possible?

6 REPLIES 6
Message 2 of 7
TheCADnoob
in reply to: atuckerJKU9U

This is a little ugly and may not work if your drawing has intelligence, but might be worth a shot. 

 

Save your DWG to a DXF. Open your DXF in Excel.

 

In Excel you can use find and replace ;* and replace it with nothing. Save the file then open the DXF in AutoCAD and save it back to a DWG. 

CADnoob

EESignature

Message 3 of 7
Kent1Cooper
in reply to: atuckerJKU9U

With the MLEADER saved as a VLA object called 'obj':

(setq str (vla-get-textstring obj))

returns [in my trial sample]"

"THIS IS; A TEST"

Then this:

(vla-put-textstring obj (substr str 1 (vl-string-search ";" str)))

replaces the text content with just:

"THIS IS"

 

EDIT:  Very lightly tested, on MLeaders, Text & Mtext:

 

(vl-load-com)
(defun C:DTASC ; = Delete Text After SemiColon
  (/ ss n obj str)
  (if (setq ss (ssget "_:L" '((0 . "*TEXT,MULTILEADER"))))
    (repeat (setq n (sslength ss))
      (setq
        obj (vlax-ename->vla-object (ssname ss (setq n (1- n))))
        str (vla-get-textstring obj)
      ); setq
      (vla-put-textstring obj (substr str 1 (vl-string-search ";" str)))
    ); repeat
  ); if
  (prin1)
)

 

Kent Cooper, AIA
Message 4 of 7
atuckerJKU9U
in reply to: TheCADnoob

Ok, that is some serious voodoo, the dxf thing.  So first I tried just exporting to dxf, opening in excel, saving under a new name and reoened in cad, and it seemed to work.  Paperspace was there, xrefs, etc.  Two problems though.  When I open it in excel, it gives an error "File not loaded completely", and when I do the find and replace, it will no longer open in cad.  I think it is finding and replacing other things besides just my target text, and it's corrupting the file.  Good suggestion though, and I learned something new about dxfs.  Good info to have in my toolbox.

Message 5 of 7
atuckerJKU9U
in reply to: Kent1Cooper

Hey Kent, that works perfectly!!  I was not expecting somebody to write a lisp for me, that was so extra, thanks!  The added benefit to this is that I can easily edit the lisp for other characters, : , etc.  Thanks so much!

Message 6 of 7
Kent1Cooper
in reply to: atuckerJKU9U

You're welcome -- a lot easier than the DXF/Excel approach, being doable all from within the drawing.  Rather than editing into separate commands for other characters, it could eastily be made to ask you for the cut-off character you want, with a default if that seems appropriate.  With some enhancement, it could be made to do the same for Dimension override text [but the name of the VLA property for that isn't the same as for those other object types].

Kent Cooper, AIA
Message 7 of 7
TheCADnoob
in reply to: atuckerJKU9U

yeah, the DXF approach probably hit the data limit on Excel if I had to guess. The drawing I tested on was really small. another pitfall would be if inside the DXF there were other entities that used the character it would swap them out as well so it's definitely not the best approach especially when someone like @Kent1Cooper can knock out a quick simple lisp haha

CADnoob

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report