Deleting specific text after a symbol

Deleting specific text after a symbol

Anonymous
Not applicable
3,239 Views
19 Replies
Message 1 of 20

Deleting specific text after a symbol

Anonymous
Not applicable

20210830_201614.jpg

 I am trying to find a way to delete all the text after the "~" symbol. If there is a way I would really appreciate  it, it will save a lot of time.

 

Thank you

0 Likes
3,240 Views
19 Replies
Replies (19)
Message 2 of 20

ennujozlagam
Mentor
Mentor

ddedit command and pick the text and erase. thanks

 

txt1s.JPG





Remember : without the difficult times in your LIFE, you wouldn't be who you are today. Be grateful for the good and the bad. ANGER doesn't solve anything. It builds nothing, but it can destroy everything...
Please mark this response as "Accept as Solution" if it answers your question. Kudos gladly accepted.
0 Likes
Message 3 of 20

ВeekeeCZ
Consultant
Consultant

Start with posting a dwg with example(s).

Also, do you mean to remove all the text behind a hyphen to the end of the line?

0 Likes
Message 4 of 20

Anonymous
Not applicable

From the ~ to the end

0 Likes
Message 5 of 20

Anonymous
Not applicable

Yes from behind the ~ to the end, sorry

0 Likes
Message 6 of 20

Kent1Cooper
Consultant
Consultant

Is that one big Mtext object, or is each line a separate Text or Mtext object?  [This kind of question is why a sample .dwg file is helpful.]

Kent Cooper, AIA
0 Likes
Message 7 of 20

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Yes from behind the ~ to the end....


If in each Text/Mtext object, try this:

(vl-load-com)
(defun C:TDAT (/ ss n tobj txt); = Text: Delete After Tilde
  (if (setq ss (ssget "_:L" '((0 . "*TEXT") (1 . "*~*"))))
    (repeat (setq n (sslength ss)); then
      (setq tobj (vlax-ename->vla-object (ssname ss (setq n (1- n)))))
      (vla-put-TextString tobj
        (substr (setq txt (vla-get-TextString tobj)) 1 (1+ (vl-string-position 126 txt)))
      ); ...put...
    ); repeat
  ); if
  (princ)
); defun

But if your image is one Mtext object, and you want such deletions for every line in it, not just the whole thing after the first ~, that's another story [but also possible].

Kent Cooper, AIA
Message 8 of 20

Anonymous
Not applicable

Every line is separate 

0 Likes
Message 9 of 20

Anonymous
Not applicable

Ah, thanks. What about if the whole thing is a block and I want it to do the same thing for every line?

0 Likes
Message 10 of 20

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... What about if the whole thing is a block and I want it to do the same thing for every line?


Do you really mean the whole thing is a Block as AutoCAD uses the term, or the whole thing is "blocked together" as one Mtext object?  It should be possible to do it either way, but the approaches would be very different.

Kent Cooper, AIA
0 Likes
Message 11 of 20

Anonymous
Not applicable

It worked but I also the ~ symbol to delete aswell

0 Likes
Message 12 of 20

Anonymous
Not applicable

Is blocked all together.

0 Likes
Message 13 of 20

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

It worked but I also the ~ symbol to delete aswell


Then the Topic heading and Message 5 should be worded differently.  But if that's what you need, change this line:

(substr (setq txt (vla-get-TextString tobj)) 1 (1+ (vl-string-position 126 txt)))

to this:

(substr (setq txt (vla-get-TextString tobj)) 1 (vl-string-position 126 txt))

And in the image, it looks like there are spaces before the ~'s.  If you also want those spaces removed, that's possible.

Kent Cooper, AIA
Message 14 of 20

jrreid
Advocate
Advocate

Easy for that, use Find Replace.

Type in Find.

Find What:   Put your ~   (if you have spaces to remove put them as well)

Replace with:  (DONT PUT ANYTHING)

Then select REPLACE ALL  or  Select the Blocks you want this to happen with.

 

If you already ran the lisp command and picked the blocks when you use find type P or Previous when selecting.

 

jrreid_0-1630428218360.png

 

Hope this helps!

 

JRR.

0 Likes
Message 15 of 20

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Is blocked all together.


That leaves the same ambiguity as before.  What is the object?  Pick it and look at the top of the Properties palette.  What does it say -- "Block Reference" or "Mtext" or something else?

Kent Cooper, AIA
0 Likes
Message 16 of 20

Anonymous
Not applicable

16304288769952174373409026285097.jpg

0 Likes
Message 17 of 20

Kent1Cooper
Consultant
Consultant

So inside the Block definition, are all the lines of text separate objects, or one Mtext object?  Get into the Block with BEDIT or REFEDIT, and you can find out.  If they're separate objects, are they in fact Text/Mtext, or are they Attribute definitions?

Kent Cooper, AIA
0 Likes
Message 18 of 20

Anonymous
Not applicable

16304330551431708377169502376545.jpg

 Not sure, but it looks like this.

0 Likes
Message 19 of 20

Kent1Cooper
Consultant
Consultant

They appear to be Attributes.  That would mean what you want to edit is the Attribute values in a particular insertion of that Block, not anything in the Block definition [what you're seeing are their tags].  FIND can do text replacements, but I don't think it can handle finding a particular character and deleting it and all that follows it, regardless of what that is.  But I don't use Attributes very much, so it would take me some research to find a way to do what you want -- maybe someone else with more Attribute experience will jump in before I get around to it. 

Kent Cooper, AIA
0 Likes
Message 20 of 20

Anonymous
Not applicable

Okay, thank you very much. I appreciate the help, previous step will help a lot though in most circumstances.

0 Likes