Easiest Way to Get Rid of MText & Text.Contents extra syntax?

Hi all,

When using Mtext & Text.Contents to see the contents of the text objects in my drawings, it has a bunch of stuff before and after the actual text. I assume these are for syntax for CAD to understand the properties set for each text. However, I am trying to have a script convert all my text to uppercase (new standard at my work), and it’s adding that syntax to SOME of the text when I use (M)Text.SetContent.

Examples:

As you can see it added the XQC; to the text once I ran my script. If all of these were consistent (i.e all XQC) I would filter it, but they’re not and they’re also not all consistently at the start of the string when using multi-line texts. So I don’t feel like I can filter it easily. Any ideas?

AllTextUpperCase_Layouts.dyn (20.8 KB)

Hi @noahling195,

I use Properties.GetParameterByName from The Civil Nodes package.
Just fetch the object and for parameter set “TEXT”

If you want to see all parameters use Properties.GetParameters

2 Likes

Thanks for the attempted solution. Unfortunately, the text parameter still contains these syntax to determine the font and what not. See example:

So that still won’t work :confused:

These are formatting codes - see here and here

You can remove manually by editing the MText, select all and remove the formatting from the ribbon > Formatting > Clear > Remove All Formatting

Then replace the paragraphs like this

Alternatives would be using Regular Expressions to clear the formatting or use MText.ExplodeFragments() method from the API

1 Like

@noahling195 Try this instead set content then:

(Selected objects should be your mtexts)

2 Likes

You are almost there, the Contents and ContentsRTF returns the text with control codes, but the Text property returns only text:

Instant edit: I see you mentioned that property before. It returns the text without control codes, but I think putting it back in the MText didn’t work quite well.

1 Like