Remove Character Formatting From Tables

Remove Character Formatting From Tables

Anonymous
Not applicable
10,367 Views
20 Replies
Message 1 of 21

Remove Character Formatting From Tables

Anonymous
Not applicable

Can anyone confirm there's no way to globally remove character formatting from tables?  I've done quite a bit of searching and found little on the topic.  Some search results mentioned the StripMtext LISP but that didn't work (I'm using AutoCAD 2017).

 

I found out a bill of material drawing I created had a different font selected which overrides the text style.  I never noticed because it displayed as simplex on my machine which is my default alternate font.  Anyway, it took quite awhile to manually remove the character formatting and I figured there must be a easier way. 

 

Thanks!

0 Likes
Accepted solutions (1)
10,368 Views
20 Replies
Replies (20)
Message 2 of 21

pbejse
Mentor
Mentor

@Anonymous wrote:

Can anyone confirm there's no way to globally remove character formatting from tables?  ..

 


Are you referring to ACAD_TABLE or something else?

0 Likes
Message 3 of 21

Anonymous
Not applicable

table.JPG

0 Likes
Message 4 of 21

pbejse
Mentor
Mentor
Accepted solution

 

(defun c:stripFormT  ( / LM:UnFormat table col row)
(defun LM:UnFormat ( str mtx / _Replace regex ) (vl-load-com)
  ;; © Lee Mac 2010
  
  (defun _Replace ( new old str )
    (vlax-put-property regex 'pattern old) (vlax-invoke regex 'replace str new)
  )
  (setq regex (vlax-get-or-create-object "VBScript.RegExp"))  
  (mapcar
    (function
      (lambda ( x ) (vlax-put-property regex (car x) (cdr x)))
    )
    (list (cons 'global actrue) (cons 'ignorecase acfalse) (cons 'multiline actrue))
  )
  (mapcar
    (function
      (lambda ( x ) (setq str (_Replace (car x) (cdr x) str)))
    )
   '(
      ("Ð"       . "\\\\\\\\")
      (" "       . "\\\\P|\\n|\\t")
      ("$1"      . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]")
      ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);")
      ("$1$2"    . "\\\\(\\\\S)|[\\\\](})|}")
      ("$1"      . "[\\\\]({)|{")
    )
  )
  (setq str
    (if mtx
      (_Replace "\\\\" "Ð" (_Replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str))
      (_Replace "\\"   "Ð" str)
    )
  )
  (vlax-release-object regex)
  str
)
  
 (if
   (setq table (ssget "_:S:E:L" '((0 . "ACAD_TABLE" ))))
   (progn
     (vla-put-regeneratetablesuppressed (setq table (vlax-ename->vla-object (ssname table 0)))  :vlax-true)
     (setq row (1- (vlax-get table 'Rows)))
     (setq col (vlax-get table 'Columns))
     
     (repeat row
     	((lambda (n)
	   	(repeat n
		  (setq n (1- n))
		  	(if (/= (setq f (vlax-invoke table 'GetText row n)) "")
			  (progn
				(setq unformatted (LM:UnFormat f nil))
		  		(vlax-invoke table 'SetText row n unformatted)))
		  			
					   )
		  		)
					  col
					)
	   (setq row (1- row))
       )
     (vla-put-regeneratetablesuppressed table :vlax-false)
     )
   )
  (princ)
  
  )
Message 5 of 21

Anonymous
Not applicable

Worked like a charm!  I didn't see this on his website but thank you for posting it!

Message 6 of 21

SKEMPP
Participant
Participant

This is a wonderful lisp, can it be modified to unlock cells if necessary? And to select multiple tables?

 

I did try, but I can't seem to get past the lambda statements.

 

Thanks if you can help

 

Steven Kemp

0 Likes
Message 7 of 21

sharpl
Advocate
Advocate

OMG, thx! Works like a clock, solid!

0 Likes
Message 8 of 21

mnorris
Contributor
Contributor

A SOLID LISP!!!!! WORKS GREAT!!!!

 

THANKS

0 Likes
Message 9 of 21

Anonymous
Not applicable

This script works almost perfect. Unfortunately it doesn't remove prefix from table text which looks like this:

{\fCalibri|b0|i0;

What could I change in this code to remove it?

I have in my table texts looks like below:

{\fCalibri|b0|i0;TEXT line 1

TEXT line 2

TEXT line 3

I need to look this like below:

TEXT line 1

TEXT line 2

TEXT line 3
0 Likes
Message 10 of 21

pbejse
Mentor
Mentor

@Anonymous wrote:

This script works almost perfect. Unfortunately it doesn't remove prefix from table text which looks like this:

{\fCalibri|b0|i0;

 

Because there could be more issues to find, which is more likely than not. please post a sample drawing.

 

 

0 Likes
Message 11 of 21

Anonymous
Not applicable

Thank you for answer, I'm attaching files:

  1. Data_source_Excel.xlsx - Excel with sample data
  2. stripFormT-usun_formatowanie_tekstu_w_tabeli.lsp - script in LSP file (the same as in this thread)
  3. Table_remove_formating_CAD.dwg - Sample drawing with table before and after the script.
Message 12 of 21

Anonymous
Not applicable

I also found that formatting depends if there are any changes inside text (bold, color change).

 

If there is no formatting inside text has value:

 

Entity value=
(1 . "{\\fCalibri|b0|i0;Simple text 1\n\nSimple text 2\n\nSimple text 3")

Text value=
{\\fCalibri|b0|i0;Simple text 1\n\nSimple text 2\n\nSimple text 3

 

no_formatting_inside.png

If there is some formatting inside text has value:

 

Entity value=
(1 . "{\\fCalibri|b0|i0|c1|p0;Simple text 1\n\\fCalibri|b1|i0|c1|p0;\\C3;\nSimple text 2\\fCalibri|b0|i0|c1|p0;\\C0;\n\nSimple text 3}")

Text value=
{\\fCalibri|b0|i0|c1|p0;Simple text 1\n\\fCalibri|b1|i0|c1|p0;\\C3;\nSimple text 2\\fCalibri|b0|i0|c1|p0;\\C0;\n\nSimple text 3}

 

with_formatting_inside.png

In both situations I wish to get as result only texts and new line chars:

 

Entity value=
(1 . "Simple text 1\n\nSimple text 2\n\nSimple text 3")

Text value=
Simple text 1\n\nSimple text 2\n\nSimple text 3

 

Attached new DWG file with changed texts in tables.

0 Likes
Message 13 of 21

pbejse
Mentor
Mentor

And how are you expecting the results to look? does it keep the "new lines" flag

  • Simple text 1
  • Simple text 2
  • Simple text 3

or simply

  • Simple text 1 Simple text 2 Simple text 3

 

EDIT: I wasnt paying attention at all, you already mentioned it at post #9 [ silly me ]

 

 

 

 

0 Likes
Message 14 of 21

Anonymous
Not applicable

I wish to keep "new lines" information. It can be also done as a choice how to treat "new lines".

0 Likes
Message 15 of 21

pbejse
Mentor
Mentor

@Anonymous wrote:

I wish to keep "new lines" information. It can be also done as a choice how to treat "new lines".


Primary reason why the code doesn't do anything is because it skips the header, [ 0 = row 1 ]

 

command: STRIPFORMT 

Keep new line format [Yes/No]: 

 

HTH

Message 16 of 21

Anonymous
Not applicable

Amazing work! It works exactly as I dreamed it! Thank you very much!

 

BTW: It is a very good idea that the option to keep "new lines" is set as the default. 👍

0 Likes
Message 17 of 21

3dwannab
Advocate
Advocate

Thanks for this,

 

I'm trying to modify this in Sublime text and after reindentation, this doesn't work.

 

I use 2 spaces as my indentation btw if that makes a difference.

 

Would you know where this problem lies? I can't find it. Thanks in advance.

 

Just found that StripMtext Version 5.0c does strip formatting from tables too. Seems to do the same anyway.

0 Likes
Message 18 of 21

spyros.maroudas.1991
Observer
Observer

In AutoCAD 2021 and 2024 (that I have tested) the stripformt routine seems to delete also the contents of all the cells of the table not only the format, does anyone know why this happens? Whereas, in 2018 it works fine. Has autodesk changed anything in the coding in between the versions? Has anyone encountered the same issue?

0 Likes
Message 19 of 21

mnorris
Contributor
Contributor

I've used the Lisp on many tables in 2024 and have not had an issue yet.

0 Likes
Message 20 of 21

stewart_carberry
Observer
Observer

It wont work for me in ACAD (vanilla) 2023.

0 Likes