strip mtext formatting

strip mtext formatting

mruPRQUJ
Advocate Advocate
8,696 Views
58 Replies
Message 1 of 59

strip mtext formatting

mruPRQUJ
Advocate
Advocate

Hi,

 

Is it possible to create a lisp to strip mtext formatting? like, width factor, tracking and oblique angle. The attached lisp can strip mtext, but not formatting. Thank you very much in advance, 🙂

0 Likes
Accepted solutions (2)
8,697 Views
58 Replies
Replies (58)
Message 41 of 59

pendean
Community Legend
Community Legend

@michellem wrote:

...I tried using it on some Mtext in a cad file exported from Revit and it had problems clearing out tabs.

 


Share a portion of that DWG file with the problematic MTEXT here when you get a chance. 

Message 42 of 59

michellem
Advocate
Advocate

Hello Pendean;

 

Coming up with examples where StripMText fails is difficult. At work, a common task is to export a bunch of Revit Drafting Views to Cad and clean them up to our company drafting standards. StripMText is a common tool used in this process and sometimes it fails. When it does, I'll either tweak StripMText if I have time and the issue is a common one, or I will just adjust the Mtext manually. Unfortunately, I do not save examples of any problems.

 

That said, I just created a sample Cad file to look at. The attached dwg file was a simple export from Revit and contains 1 MText entity. StripMtext v5-0c (the current version?) fails to remove the tabs in that MText. I tweaked it as shown in the lisp file StripMtext v5-0d to fix that issue. I am not sure how robust or complete that fix was, however.

So I am hoping that there may be a newer StripMtext out there that fixes issues and incorporates the newer formatting options available in MText entities.

 

Sincerely;

Michelle

 

0 Likes
Message 43 of 59

pendean
Community Legend
Community Legend

@michellem See attached, 5c-version removed all the tabs. What did I miss (other than I did not save it back down to 2013DWG format of course).

Message 44 of 59

michellem
Advocate
Advocate

Hmm...That is peculiar. Different settings perhaps? 

Here is what I see before doing anything:

michellem_0-1704319097876.png

Here I am running version C:

michellem_1-1704319176758.png

Here is what I have after running version C:

michellem_2-1704319271678.png

Michelle

 

0 Likes
Message 45 of 59

michellem
Advocate
Advocate

PS, I am working at home today and all I have here is AutoCad 2016 (perpetual license).

0 Likes
Message 46 of 59

pendean
Community Legend
Community Legend

@michellem wrote:

Hmm...That is peculiar. Different settings perhaps? 

michellem_1-1704319176758.png

 

 


Why not test the other options (or combos of them)? I had all selected for my quick test with your file.

 

I'm running AutoCAD 2023.

Message 47 of 59

michellem
Advocate
Advocate

Well, it seems that selecting the Paragraph (and only the paragraph option) will remove the tab stops. As near as I can tell without a lot of testing is that version C does not know what to do with \pxt code and so the tab removal option fails to find the tab stops. The paragraph removal option then comes along and finds the \p in the \pxt. It removes the \p which results in illegal formatting and then Autocad strips that out before allowing the user to manually access the MText.

 

I suspect Autocad changed the formatting codes for tabs somewhere along the line. If that is the case, I wonder if the old formatting code would still be recognized by Autocad?

 

My fix searches for \pxt but might have unintended consequences when it comes time to process the paragraph.

0 Likes
Message 48 of 59

john.uhden
Mentor
Mentor

Ya know.  I don't remember what the tab codes look like, but their spacing is not necessarily uniform.  They can be all over the place, which may cause what appear to be failures.

John F. Uhden

Message 49 of 59

michellem
Advocate
Advocate

At any rate, the main question still remains: Is there a newer version of StripMText out there?

0 Likes
Message 50 of 59

Sea-Haven
Mentor
Mentor

Looking at sample, maybe look for "{" then read string from that point, then run stripmtext.

 

(setq obj (vlax-ename->vla-object (car  (entsel "Pick mtext "))))
(setq str (vlax-get obj 'textstring))
"\\pxt1.33333,2.66667,4,5.33333,6.66667,8,9.33333,10.66667,12,13.33333,
14.66667,16,17.33333,18.66667,20,21.33333,22.66667,24,25.33333,26.66667,
28,29.33333,30.66667,32,33.33333,34.66667,36,37.33333,38.66667,40,
41.33333,42.66667;{happy to see you\\POff to work I go}"

(setq x (vl-string-position 123 str))
(setq y (vl-string-position 125 str))
(setq str2 (substr str (+ 2 x) (- y x 1)))
"happy to see you\\POff to work I go"

 

Need a lot more samples to really test.

Message 51 of 59

john.uhden
Mentor
Mentor

@Sea-Haven ,

After a cursory examination of an Mtext with tabs. it appears that:

1.  There is one string of formatting per paragraph that specifies where the tab stop(s) are...

     \\P\\pxt10,15;

2.  There is one  "\t" at each point in the textstring where a tab should be inserted (in order of the defined tab stops).

 

Which leaves me with the question...

Do we want to remove just the tabs, or just the tab stop definition, or both?

John F. Uhden

Message 52 of 59

john.uhden
Mentor
Mentor

@mruPRQUJ ,

Now that I think about it a little more, why would one want to delete tabs?

It's not like overrides for color or width factor or font.  It's about the organization of the paragraphs of text within an mtext or mleader so that the contents line up properly without having to use a table.

We have a self-proclaimed CAD guru at work who hates tables and relies on mtext instead.  Of course he doesn't format any tab stops at all, but just uses the defaults, which results in an unbalanced product, maybe wider or narrower than one would like, but the info ends up organized by columns (once applying spaces where needed), so I guess it's just fine.

But what do I know?

John F. Uhden

Message 53 of 59

michellem
Advocate
Advocate

Hello John;

 

Why delete tab stops? Cad exports from Revit!

 

In Revit, text is an annotative object which automatically changes height based on the scale of the detail. One cannot set individual tab stops but only change the default spacing of the tabs. Furthermore, tab spacing is a property of the text style - need a different spacing at a specific location? Create a new text style. Revit also uses the default tab spacing for bulleted lists.

 

I mention Revit, because our firm often exports details from Revit to Cad and vice-versa. Text exported by Revit becomes an MText entity with individual tab stops set for every default tab location. Say you have a Revit TextNote with a ht of 3/32" that is 2" wide with a default tab spacing of 1/8" in a detail with a scale of 1 = 1, Revit will create an MText entity that is 3/32" high x 2" wide and have 15 individual tab stops. A TextNote used for general notes can up to 7" wide.

 

That is a whole lot of tab stops on the MText ruler that I am better off without.

 

Michelle

0 Likes
Message 54 of 59

ВeekeeCZ
Consultant
Consultant

@michellem wrote:

... StripMtext v5-0c (the current version?) fails to remove the tabs in that MText. I tweaked it as shown in the lisp file StripMtext v5-0d to fix that issue...

 

Michelle

 


 

FYI

One little tweak was already added to the c version a few years back by @cadffm 

https://ww3.cad.de/foren/ubb/uploads/cadffm/StripMtextv5-0d.lsp

Message 55 of 59

wes.sheffer
Contributor
Contributor

Just a friendly reminder for posterity, if like me you came to this thread having no success figuring out how to strip width factor from Mtext, don't forget to check whether it is set as a property of the text style (STYLE command).  StripMtext wouldn't set my text's width factor from 1.3 back to 1, and the in-editor right click menu item "Remove Character Formatting" wouldn't do it either.  Face palm when I realized there never was an override because the 1.3 width factor was defined in the text style.

wessheffer_0-1724257354883.png

 

0 Likes
Message 56 of 59

JerryHGE
Observer
Observer

Hello, sorry, new here.  I would very much like to have your newest mtext stripper that also handles mleaders, how can i get it?

 

jerry.s

jschultz@hge1.com

0 Likes
Message 57 of 59

pkenewell6347
Advocate
Advocate
0 Likes
Message 58 of 59

m_beach89
Participant
Participant

Hey, I would like to find a lisp like stripmtext but one which works on the text format of block attribute values.  Over the last 2 years, I have created about 100 blocks with 50ish attributes each where I copy/pasted the attributes who's default value text color was formatted with ByLayer and I want to change it to ByBlock (strip the color format).  To clarify, I don't want to change the attribute property, I need to change the text formatting of the block attribute's default value, so I am forced to edit each one individually select all text and change the format.  This will take ages.  Can anyone help?

0 Likes
Message 59 of 59

m_beach89
Participant
Participant

Okay, I've found an acceptable solution, it's a bit manual, and only works if the offending block is a nested block, but I can edit all the attributes of all the nested blocks at the same time (which saves 95% of the time I would have spent on doing each one by one).  Because the attributes are of the nested block, they retain their given values (and formatting) when I write the block out to the block library, in other words the actual default value formatting doesn't matter.  So for anyone else with a similar issue, listen up:

 

1) open the block editor with the nested blocks and run the ATTOUT command on all of them

2) open the .txt file and replace the formatting (i.e. {\C256; and }) with nothing to strip all the attributes of unwanted formatting at the same time

3) save the .txt file and run the ATTIN command, then save and close block editor and write the block out again

 

Again, this process does not update the formatting for the default values of the block attributes, but due to the nature of nested blocks, it's nearly indistinguishable.  Hope this helps someone 🙂

 

 

0 Likes