Strip formatting from text (not mtext) objects

Strip formatting from text (not mtext) objects

Netelaana
Enthusiast Enthusiast
420 Views
8 Replies
Message 1 of 9

Strip formatting from text (not mtext) objects

Netelaana
Enthusiast
Enthusiast

I have many, many text objects throughout a large drawing with embedded strike-through "%%K" formatting.

 

The text string looks like some variation of "PROPOSED%%K S%%KLEEVE"

 

I would like to strip out all such formatting. I have tried using "StripMtext Version 5.0c" lisp, find and replace, etc. with no success.

 

I also tried converting the text to mtext first  and then running "StripMtext", but it does not remove the "\k" associated with the strike-through once converted to mtext. I feel as if there should be a simple lisp solution for this issue, but I can't put my finger on it. 

 

An ideal solution would be a "find and replace" approach as the text objects are on multiple layouts and embedded in blocks.

 

Thanks in advance for any pointers!

0 Likes
Accepted solutions (1)
421 Views
8 Replies
Replies (8)
Message 2 of 9

paullimapa
Mentor
Mentor

If these Texts are not inside blocks then you can try DDTXTS&R.LSP which is included as an added sample routine in my free TextApps:

https://apps.autodesk.com/ACD/en/Detail/Index?id=5878795472985504811&appLang=en&os=Win32_64

After downloading & installing TextApps the sample DDTXTS&R.LSP can be found in the installed folder under your profile:

"C:\Users\your windows login profile\AppData\Roaming\Autodesk\ApplicationPlugins\TextApps.bundle\Contents\Windows\DDTXTS&R.LSP"

Drag & drop DDTXTS&R.LSPinto the dwg then enter DDTXTS&R to run the code.

Enter ALL to select all Text objects

In the Search & Replace Text window that appears search for %%K & replace with nothing:

 

paullimapa_1-1753811443124.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 9

pbejse
Mentor
Mentor
Accepted solution

@Netelaana wrote:

I have many, many text objects throughout a large drawing with embedded strike-through "%%K" formatting.

 

The text string looks like some variation of "PROPOSED%%K S%%KLEEVE"

 

I would like to strip out all such formatting. I have tried using "StripMtext Version 5.0c" lisp, find and replace, etc. with no success.

 

I also tried converting the text to mtext first  and then running "StripMtext", but it does not remove the "\k" associated with the strike-through once converted to mtext. I feel as if there should be a simple lisp solution for this issue, but I can't put my finger on it. 

 

An ideal solution would be a "find and replace" approach as the text objects are on multiple layouts and embedded in blocks.

 

Thanks in advance for any pointers!


(defun c:StrippedStrikeAll (/ aDoc stringValue)
  (setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vlax-for blk	(vla-get-blocks aDoc)
    (eq :vlax-false (vla-get-isXref blk))
	    (vlax-for h	blk
	      (if
		(and (vlax-write-enabled-p h)
		     (eq (vla-get-ObjectName h) "AcDbText")
		     (setq stringValue (Vla-get-Textstring h))
		)
		 (progn
		   (while (vl-string-search "%%K" stringValue)
		     (setq stringValue (Vl-string-subst "" "%%K" stringValue))
		   )
		   (vla-put-textstring h stringValue)
		 )
	      )
	    )
  )
  (princ)
)

May require a regen

 

HTH

0 Likes
Message 4 of 9

Netelaana
Enthusiast
Enthusiast

Thank you! Worked wonderfully.

Hours of tedium averted. 

0 Likes
Message 5 of 9

paullimapa
Mentor
Mentor

FYI I think this line of code has an additional c:

(defun c:c:StrippedStrikeAll (/ aDoc stringValue)

 It should be this 

(defun c:StrippedStrikeAll (/ aDoc stringValue)

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 9

pbejse
Mentor
Mentor

Thank you for spotting that @paullimapa 

 

Cheers beer.gif

0 Likes
Message 7 of 9

pbejse
Mentor
Mentor

Glad it works for you 🙂

 

Happy to help

 

0 Likes
Message 8 of 9

paullimapa
Mentor
Mentor

you are welcome...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 9 of 9

Kent1Cooper
Consultant
Consultant

Since the strike-through coding can use either a lower- or upper-case K, here's a version [also with a different approach] that catches either of those [lightly tested]:

(defun C:UST ; = Un-Strike-Through
  (/ ss n txt str)
  (if (setq ss (ssget "_X" '((0 . "TEXT") (1 . "*[Kk]*"))))
    (repeat (setq n (sslength ss)); then
      (setq
        txt (ssname ss (setq n (1- n)))
        str (getpropertyvalue txt "TextString")
      ); setq
      (while (wcmatch (strcase str) "*%%K*")
        (setpropertyvalue txt "TextString"
          (setq str (vl-string-subst "" "%%k" (vl-string-subst "" "%%K" str)))
        ); set...
      ); while
    ); repeat
  ); if
  (prin1)
)

It doesn't check all Text, but limits itself to only Text objects that contain such coding, even if with mixed %%K and %%k formats.

Kent Cooper, AIA
0 Likes